diff --git a/src/App.vue b/src/App.vue index 25bd39f..2f40c85 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,13 +1,13 @@ diff --git a/src/router/index.js b/src/router/index.js index 7d35183..706e7e6 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -9,11 +9,6 @@ const routes = [ name: 'Home', component: () => import(/* webpackChunkName: "home" */ '../views/Home/Home.vue') }, - { - path: '/search', - name: 'Search', - component: () => import(/* webpackChunkName: "search" */ '../views/Search/Search.vue') - }, { path: '/add', name: 'Add', @@ -44,6 +39,17 @@ const routes = [ name: 'Unlock', component: () => import(/* webpackChunkName: "unlock" */ '../views/Unlock/Unlock.vue') }, + { + path: '/detail', + name: 'Detail', + component: () => import(/* webpackChunkName: "detail" */ '../views/Detail/Detail.vue') + }, + { + path: '*', // 页面不存在的情况下会跳到home + redirect: '/', + name: 'notFound', + hidden: true + } ] const router = new VueRouter({ diff --git a/src/svg/canary-white.svg b/src/svg/canary-white.svg new file mode 100644 index 0000000..b12ffbd --- /dev/null +++ b/src/svg/canary-white.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/views/Detail/Detail.vue b/src/views/Detail/Detail.vue new file mode 100644 index 0000000..05fb06e --- /dev/null +++ b/src/views/Detail/Detail.vue @@ -0,0 +1,246 @@ + + + + + diff --git a/src/views/Home/Home.vue b/src/views/Home/Home.vue index 89ddd97..9966fd8 100644 --- a/src/views/Home/Home.vue +++ b/src/views/Home/Home.vue @@ -17,7 +17,7 @@
- +
@@ -102,12 +102,14 @@ export default { clientHeight: '', // 显示的密码列表 show_list: [], + // 搜索暂存list + cache_list: [], unlock: false, show_snackbar: false, snakebar_msg: '', web_addr: 'https://codebook.canary.moe', - employees: [], - selectedEmployee: null, + titles: [], + search_content: '', search_start: false }; }, @@ -144,7 +146,10 @@ export default { // 解密密码本 let data_decrypt = decrypt(main_code_decrpt, this.row_data); // 刷新显示内容 - this.show_list = JSON.parse(data_decrypt); + let data_list = JSON.parse(data_decrypt); + this.show_list = data_list + // 抽离title + this.separateTitle(data_list) } else { // 空密码本 this.show_list = []; @@ -236,15 +241,48 @@ export default { // 复制成功 onCopyUrl(e) { - this.snakebar_msg = '复制成功'; + this.snakebar_msg = 'Copy successful'; this.show_snackbar = true; }, // 复制失败 onErrorUrl(e) { - this.snakebar_msg = '复制失败,夸克等浏览器复制成功仍会显示失败'; + this.snakebar_msg = 'Failed to copy, but failed in some cases. Try to paste'; this.show_snackbar = true; - } + }, + + // 分离数据title + separateTitle(data_list) { + let title_list = [] + for(let i in data_list) { + title_list.push(data_list[i].title) + } + this.titles = title_list + console.log('数据头部分离完成') + }, + + // 模糊搜索 + fuzzySearch(cache_list) { + // 空内容拦截器,显示全部密码 + if(!this.search_content.trim()) { + this.show_list = cache_list + return + } + let data_list = [] + for (let i in cache_list) { + if(this.generReg(this.search_content.trim()).test(cache_list[i].title)) { + data_list.push(cache_list[i]) + } + } + this.show_list = data_list + }, + + generReg(val) { + let head = '(.*)(' + let tail = ')(.*)' + let body = val.split('').join(')(.*)(') + return new RegExp(head + body + tail, 'i') + }, }, created() { // 重置row_pwd @@ -264,6 +302,21 @@ export default { // 如果 `clientHeight` 发生改变,这个函数就会运行 clientHeight: function() { this.changeFixed(this.clientHeight); + }, + // 如果 `search_start` 发生改变,这个函数就会运行 + search_start: function() { + if(this.search_start) { + this.cache_list = JSON.parse(JSON.stringify(this.show_list)) + console.log('搜索阵列展开,缓存设置完成') + } else { + this.show_list = JSON.parse(JSON.stringify(this.cache_list)) + this.cache_list = [] + console.log('搜索阵列关闭,缓存清空完成') + } + }, + // 如果 `search_content` 发生改变,这个函数就会运行 + search_content: function() { + this.fuzzySearch(this.cache_list) } }, beforeDestroy() {}, @@ -284,6 +337,7 @@ export default { box-sizing: border-box; background: $main-color; color: #fff; + position: relative; .default-avatar { color: #fff; margin-bottom: 0.3rem; diff --git a/src/views/Search/Search.vue b/src/views/Search/Search.vue deleted file mode 100644 index 660278f..0000000 --- a/src/views/Search/Search.vue +++ /dev/null @@ -1,188 +0,0 @@ - - - - - \ No newline at end of file