2021-02-10 01:31:50 +08:00
|
|
|
|
<template>
|
|
|
|
|
<el-container class="tools">
|
|
|
|
|
|
2021-04-06 20:51:00 +08:00
|
|
|
|
<div class="wrapper">
|
|
|
|
|
|
2021-05-03 00:56:11 +08:00
|
|
|
|
<!-- 工具分类 -->
|
|
|
|
|
<div v-for="(categoryItem, categoryKey) in toolList" :key="categoryKey" class="category">
|
|
|
|
|
|
|
|
|
|
<!-- 标题 -->
|
|
|
|
|
<div class="title">{{ categoryItem.title }}</div>
|
|
|
|
|
|
|
|
|
|
<!-- 工具项 -->
|
|
|
|
|
<div v-for="(toolItem, toolKey) in categoryItem.list" :key="toolKey"
|
|
|
|
|
:class="['tool-item', 'shadow-2', { disabled: !toolItem.enabled }]"
|
2021-05-04 19:18:57 +08:00
|
|
|
|
@click="detailOpen(categoryKey, toolKey)"
|
2021-05-03 00:56:11 +08:00
|
|
|
|
>
|
|
|
|
|
<div class="item-title limit-line-1">{{ toolItem.title }}</div>
|
|
|
|
|
<div class="item-content limit-line-3">{{ toolItem.desc || '无简介' }}</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2021-04-06 20:51:00 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- 弹出 -->
|
2021-05-04 00:33:16 +08:00
|
|
|
|
<el-drawer custom-class="drawer-full" direction="btt" size="100%"
|
|
|
|
|
:append-to-body="true" :destroy-on-close="true" :title="detail.title"
|
2021-05-04 19:18:57 +08:00
|
|
|
|
:visible.sync="detail.show" :before-close="detailClose"
|
2021-04-06 20:51:00 +08:00
|
|
|
|
>
|
2021-05-04 19:18:57 +08:00
|
|
|
|
|
|
|
|
|
<!-- 标题区域 -->
|
|
|
|
|
<div slot="title" class="header">
|
|
|
|
|
<span class="title">{{ detail.title }}</span>
|
|
|
|
|
<el-tooltip content="在新标签页中打开本工具" placement="left">
|
|
|
|
|
<i class="btn el-icon-copy-document" @click="detailOpenNewTab()"></i>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- 内容区域 -->
|
2021-05-04 00:33:16 +08:00
|
|
|
|
<router-view></router-view>
|
2021-05-04 19:18:57 +08:00
|
|
|
|
|
2021-04-06 20:51:00 +08:00
|
|
|
|
</el-drawer>
|
|
|
|
|
|
2021-02-10 01:31:50 +08:00
|
|
|
|
</el-container>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2021-05-03 00:56:11 +08:00
|
|
|
|
import navTools from '@/assets/js/navTools.js';
|
|
|
|
|
|
2021-02-10 01:31:50 +08:00
|
|
|
|
export default {
|
|
|
|
|
name: 'Tools',
|
2021-11-08 17:46:16 +08:00
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
utils: this.$root.utils,
|
|
|
|
|
toolList: navTools,
|
|
|
|
|
detail: {
|
|
|
|
|
show: false,
|
|
|
|
|
title: ''
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-05-23 23:35:58 +08:00
|
|
|
|
beforeRouteEnter(to, from, next) {
|
|
|
|
|
next(vm => {
|
|
|
|
|
var route = vm.$route;
|
|
|
|
|
|
|
|
|
|
// 判断进入的路由
|
2021-07-05 23:15:24 +08:00
|
|
|
|
if (route.name === 'ToolsDetail') {
|
2021-05-23 23:35:58 +08:00
|
|
|
|
// 进入:工具内容页面
|
|
|
|
|
vm.detailOpen(route.params.category, route.params.name);
|
|
|
|
|
} else {
|
|
|
|
|
// 进入:工具列表页面
|
|
|
|
|
vm.utils.changeTitle('小工具');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2021-04-06 20:51:00 +08:00
|
|
|
|
methods: {
|
2021-05-03 00:56:11 +08:00
|
|
|
|
|
2021-05-04 19:18:57 +08:00
|
|
|
|
/**
|
|
|
|
|
* 关闭工具
|
|
|
|
|
*/
|
|
|
|
|
detailClose(done) {
|
|
|
|
|
this.$confirm('是否关闭?').then(() => {
|
|
|
|
|
// 关闭 drawer
|
|
|
|
|
done();
|
|
|
|
|
// 路由跳转
|
|
|
|
|
this.$router.push({
|
|
|
|
|
name: 'Tools'
|
|
|
|
|
});
|
|
|
|
|
// 更新页面标题
|
|
|
|
|
this.utils.changeTitle('小工具');
|
|
|
|
|
}).catch(() => { });
|
|
|
|
|
},
|
|
|
|
|
|
2021-05-03 00:56:11 +08:00
|
|
|
|
/**
|
|
|
|
|
* 打开工具
|
2021-05-04 19:18:57 +08:00
|
|
|
|
*
|
|
|
|
|
* @param {string} toolCatrgory 工具分类
|
|
|
|
|
* @param {string} toolName 工具名称
|
2021-05-03 00:56:11 +08:00
|
|
|
|
*/
|
2021-05-04 19:18:57 +08:00
|
|
|
|
detailOpen(toolCatrgory, toolName) {
|
2021-05-09 14:27:52 +08:00
|
|
|
|
var vm = this;
|
2021-04-06 20:51:00 +08:00
|
|
|
|
// 当前工具信息
|
2021-05-03 00:56:11 +08:00
|
|
|
|
var info = {};
|
2021-05-09 14:27:52 +08:00
|
|
|
|
// 错误提示
|
|
|
|
|
var errMsg = `无法打开该工具(分类:${toolCatrgory} 名称:${toolName})`;
|
2021-11-08 17:46:16 +08:00
|
|
|
|
|
2021-05-03 00:56:11 +08:00
|
|
|
|
try {
|
|
|
|
|
|
2021-05-09 14:27:52 +08:00
|
|
|
|
info = vm.toolList[toolCatrgory]['list'][toolName];
|
2021-05-03 00:56:11 +08:00
|
|
|
|
|
|
|
|
|
if (info === undefined) {
|
2021-05-09 14:27:52 +08:00
|
|
|
|
throw new Error(errMsg);
|
2021-05-03 00:56:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
2021-05-09 14:27:52 +08:00
|
|
|
|
|
2021-05-03 00:56:11 +08:00
|
|
|
|
console.warn('[打开工具]', err);
|
2021-05-09 14:27:52 +08:00
|
|
|
|
vm.$message({
|
|
|
|
|
message: errMsg,
|
|
|
|
|
type: 'warning'
|
|
|
|
|
});
|
2021-05-03 00:56:11 +08:00
|
|
|
|
return;
|
2021-04-06 20:51:00 +08:00
|
|
|
|
|
2021-05-03 00:56:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 禁用
|
|
|
|
|
if (!info.enabled) {
|
2021-05-09 14:27:52 +08:00
|
|
|
|
vm.$message({
|
2021-05-03 00:56:11 +08:00
|
|
|
|
message: '该工具未启用',
|
|
|
|
|
type: 'warning'
|
|
|
|
|
});
|
2021-04-06 20:51:00 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新页面标题
|
2021-05-09 14:27:52 +08:00
|
|
|
|
vm.utils.changeTitle(info.title);
|
2021-04-06 20:51:00 +08:00
|
|
|
|
// 更新 drawer 标题
|
2021-11-08 17:46:16 +08:00
|
|
|
|
vm.detail.title = `${info.title} [${info.version}][${info.update}]`;
|
2021-04-06 20:51:00 +08:00
|
|
|
|
// 路由跳转
|
2021-05-05 19:22:08 +08:00
|
|
|
|
// 注:当前路由相同时也进行跳转,以更新 query
|
2021-05-09 14:27:52 +08:00
|
|
|
|
vm.$router.push({
|
2021-04-06 20:51:00 +08:00
|
|
|
|
name: 'ToolsDetail',
|
2021-05-03 00:56:11 +08:00
|
|
|
|
params: {
|
|
|
|
|
category: toolCatrgory,
|
|
|
|
|
name: toolName
|
2021-04-06 20:51:00 +08:00
|
|
|
|
}
|
2021-05-03 00:56:11 +08:00
|
|
|
|
}).catch((err) => {
|
|
|
|
|
console.log('[路由跳转]', err.name);
|
2021-04-06 20:51:00 +08:00
|
|
|
|
});
|
|
|
|
|
// 显示 drawer
|
2021-05-09 14:27:52 +08:00
|
|
|
|
vm.detail.show = true;
|
2021-04-06 20:51:00 +08:00
|
|
|
|
},
|
2021-05-03 00:56:11 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2021-05-04 19:18:57 +08:00
|
|
|
|
* 打开工具(新标签页)
|
2021-05-03 00:56:11 +08:00
|
|
|
|
*/
|
2021-05-04 19:18:57 +08:00
|
|
|
|
detailOpenNewTab() {
|
|
|
|
|
var url = window.location.href;
|
|
|
|
|
|
|
|
|
|
window.open(url, '_blank');
|
2021-11-08 17:46:16 +08:00
|
|
|
|
},
|
2021-05-03 00:56:11 +08:00
|
|
|
|
|
2021-04-06 20:51:00 +08:00
|
|
|
|
},
|
2021-02-10 01:31:50 +08:00
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="less" scoped>
|
2021-04-06 20:51:00 +08:00
|
|
|
|
.tools {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
align-items: center;
|
|
|
|
|
padding: 2rem;
|
|
|
|
|
background-color: @colorWhite;
|
2021-05-03 00:56:11 +08:00
|
|
|
|
overflow-y: auto;
|
2021-04-06 20:51:00 +08:00
|
|
|
|
|
|
|
|
|
.wrapper {
|
2021-05-03 00:56:11 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.category {
|
2021-04-06 20:51:00 +08:00
|
|
|
|
display: flex;
|
2021-11-07 11:30:29 +08:00
|
|
|
|
align-items: flex-start;
|
2021-04-06 20:51:00 +08:00
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
justify-content: flex-start;
|
2021-05-03 00:56:11 +08:00
|
|
|
|
position: relative;
|
|
|
|
|
padding-top: 3rem;
|
2021-04-06 20:51:00 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
|
2021-05-03 00:56:11 +08:00
|
|
|
|
.title {
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 1rem;
|
|
|
|
|
left: 0;
|
2021-04-06 20:51:00 +08:00
|
|
|
|
font-weight: bold;
|
2021-06-14 00:58:13 +08:00
|
|
|
|
color: @textPrimary;
|
2021-04-06 20:51:00 +08:00
|
|
|
|
}
|
2021-02-10 01:31:50 +08:00
|
|
|
|
|
2021-05-03 00:56:11 +08:00
|
|
|
|
.tool-item {
|
|
|
|
|
flex-shrink: 0;
|
2021-06-05 11:08:28 +08:00
|
|
|
|
margin: 0.5rem;
|
2021-05-03 00:56:11 +08:00
|
|
|
|
padding: 1rem;
|
2021-05-28 22:09:44 +08:00
|
|
|
|
width: 16rem;
|
2021-06-05 11:08:28 +08:00
|
|
|
|
border-left: 0.2rem solid @colorPrimary;
|
|
|
|
|
border-radius: 0.25rem;
|
2021-05-03 00:56:11 +08:00
|
|
|
|
background-color: #FFF;
|
|
|
|
|
font-size: 0;
|
2021-06-14 00:58:13 +08:00
|
|
|
|
color: @textPrimary;
|
2021-05-03 00:56:11 +08:00
|
|
|
|
overflow: hidden;
|
|
|
|
|
transition: all @transitionTime;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
border-left-color: @colorSecondary;
|
2021-06-05 11:08:28 +08:00
|
|
|
|
transform: translateY(-0.2rem);
|
2021-05-03 00:56:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&.disabled {
|
|
|
|
|
border-left-color: @colorGrey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.item-title {
|
2021-06-05 11:08:28 +08:00
|
|
|
|
margin-bottom: 0.5rem;
|
2021-05-03 00:56:11 +08:00
|
|
|
|
font-weight: bold;
|
2021-06-05 11:08:28 +08:00
|
|
|
|
font-size: 0.9rem;
|
2021-05-03 00:56:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.item-content {
|
2021-05-28 22:09:44 +08:00
|
|
|
|
height: calc(1.5em * 2);
|
2021-05-03 00:56:11 +08:00
|
|
|
|
line-height: 1.5em;
|
2021-06-05 11:08:28 +08:00
|
|
|
|
font-size: 0.75rem;
|
2021-06-14 00:58:13 +08:00
|
|
|
|
color: @textSecondary;
|
2021-05-03 00:56:11 +08:00
|
|
|
|
}
|
2021-04-06 20:51:00 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-04 19:18:57 +08:00
|
|
|
|
|
|
|
|
|
.drawer-full {
|
|
|
|
|
.header {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
|
|
|
|
.btn {
|
|
|
|
|
margin: 0 0.5rem;
|
|
|
|
|
font-size: inherit;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-10 01:31:50 +08:00
|
|
|
|
</style>
|