diff --git a/src/api/address_book.js b/src/api/address_book.js index 648945d..c875f06 100644 --- a/src/api/address_book.js +++ b/src/api/address_book.js @@ -37,9 +37,9 @@ export function remove (data) { }) } -export function changePwd (data) { +export function batchCreate (data) { return request({ - url: '/address_book/changePwd', + url: '/address_book/batchCreate', method: 'post', data, }) diff --git a/src/api/peer.js b/src/api/peer.js index 21c17ea..646c9bd 100644 --- a/src/api/peer.js +++ b/src/api/peer.js @@ -36,3 +36,11 @@ export function remove (data) { data, }) } + +export function batchRemove (data) { + return request({ + url: '/peer/batchDelete', + method: 'post', + data, + }) +} diff --git a/src/store/app.js b/src/store/app.js index b1e32f7..8a6ec89 100644 --- a/src/store/app.js +++ b/src/store/app.js @@ -11,7 +11,7 @@ export const useAppStore = defineStore({ sideIsCollapse: false, logo, lang: localStorage.getItem('lang') || 'zh-CN', - locale: zhCn, + locale: localStorage.getItem('lang') === 'en' ? en : zhCn, }, }), diff --git a/src/styles/style.scss b/src/styles/style.scss index 251dc82..db8e424 100644 --- a/src/styles/style.scss +++ b/src/styles/style.scss @@ -10,11 +10,21 @@ $sideBarWidth: 210px; --primaryColor: #409eff; } -.list-body{ +.list-body { margin: 10px 0; } -.dialog-form{ +.dialog-form { max-width: 600px; margin: 20px auto; } + +.list-query { + .el-select { + --el-select-width: 160px; + } + + .el-input { + --el-input-width: 160px; + } +} diff --git a/src/utils/file.js b/src/utils/file.js index a4f07cd..fa84f9f 100644 --- a/src/utils/file.js +++ b/src/utils/file.js @@ -1,4 +1,4 @@ -export function get_suffix(filename) { +export function get_suffix (filename) { var pos = filename.lastIndexOf('.') var suffix = '' if (pos !== -1) { @@ -7,7 +7,7 @@ export function get_suffix(filename) { return suffix } -export function random_string(len) { +export function random_string (len) { len = len || 32 var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678' var maxPos = chars.length @@ -18,17 +18,40 @@ export function random_string(len) { return pwd } -export function random_filename(filename) { +export function random_filename (filename) { var suffix = get_suffix(filename) var time = new Date() var time2 = new Date('2020/01/01') return Math.ceil((time.getTime() - time2.getTime()) / 1000) + '_' + random_string(10) + suffix } -export function utf8_to_b64(str) { +export function utf8_to_b64 (str) { return window.btoa(unescape(encodeURIComponent(str))) } -export function b64_to_utf8(str) { +export function b64_to_utf8 (str) { return decodeURIComponent(escape(window.atob(str))) } + +export function jsonToCsv (data) { + let csv = '' + let keys = Object.keys(data[0]) + csv += keys.join(',') + '\n' + data.forEach(row => { + csv += keys.map(key => `"${row[key]}"`).join(',') + '\n' + }) + return new Blob([csv], { type: 'text/csv' }) +} + +export function downBlob (blob, filename) { + const url = window.URL.createObjectURL(blob) + const a = document.createElement('a') + a.href = url + a.download = filename + document.body.appendChild(a) + a.click() + setTimeout(() => { + window.URL.revokeObjectURL(url) + document.body.removeChild(a) + }) +} diff --git a/src/utils/i18n.js b/src/utils/i18n.js index 435826b..8dbc60e 100644 --- a/src/utils/i18n.js +++ b/src/utils/i18n.js @@ -1,17 +1,16 @@ import en from '@/utils/i18n/en.json' import zhCN from '@/utils/i18n/zh_CN.json' import { useAppStore } from '@/store/app' -import { pinia } from '@/store' export function T (key, params, num = 0) { - const appStore = useAppStore(pinia) + const appStore = useAppStore() const lang = appStore.setting.lang const trans = lang === 'zh-CN' ? zhCN : en const tran = trans[key] if (!tran) { return key } - const msg = num > 0 ? (tran.Other ? tran.Other : tran.One) : tran.One + const msg = num > 1 ? (tran.Other ? tran.Other : tran.One) : tran.One //msg 是这样 {name} is name //params 是这样 {name: 'zhangsan'} //替换 diff --git a/src/utils/i18n/en.json b/src/utils/i18n/en.json index 6ffa99a..d54b90f 100644 --- a/src/utils/i18n/en.json +++ b/src/utils/i18n/en.json @@ -232,5 +232,55 @@ }, "LoginLog": { "One": "Login Log" + }, + "LastOnlineTime": { + "One": "Last Online Time" + }, + "JustNow": { + "One": "Just Now" + }, + "MinutesAgo": { + "One": "{param} Minute Ago", + "Other": "{param} Minutes Ago" + }, + "HoursAgo": { + "One": "{param} Hour Ago", + "Other": "{param} Hours Ago" + }, + "DaysAgo": { + "One": "{param} Day Ago", + "Other": "{param} Days Ago" + }, + "MonthsAgo": { + "One": "{param} Month Ago", + "Other": "{param} Months Ago" + }, + "YearsAgo": { + "One": "{param} Year Ago", + "Other": "{param} Years Ago" + }, + "MinutesLess": { + "One": "Less than {param} minute", + "Other": "Less than {param} minutes" + }, + "HoursLess": { + "One": "Less than {param} hour", + "Other": "Less than {param} hours" + }, + "DaysLess": { + "One": "Less than {param} day", + "Other": "Less than {param} days" + }, + "Export": { + "One": "Export" + }, + "AddToAddressBook": { + "One": "Add To Address Book" + }, + "BatchDelete": { + "One": "Batch Delete" + }, + "PleaseSelectData": { + "One": "Please select data" } } diff --git a/src/utils/i18n/zh_CN.json b/src/utils/i18n/zh_CN.json index cfb18e4..f34f7a9 100644 --- a/src/utils/i18n/zh_CN.json +++ b/src/utils/i18n/zh_CN.json @@ -232,5 +232,47 @@ }, "LoginLog": { "One": "登录日志" + }, + "LastOnlineTime": { + "One": "最后在线时间" + }, + "JustNow": { + "One": "刚刚" + }, + "MinutesAgo": { + "One": "{param} 分钟前" + }, + "HoursAgo": { + "One": "{param} 小时前" + }, + "DaysAgo": { + "One": "{param} 天前" + }, + "MonthsAgo": { + "One": "{param} 月前" + }, + "YearsAgo": { + "One": "{param} 年前" + }, + "MinutesLess": { + "One": "{param} 分钟内" + }, + "HoursLess": { + "One": "{param} 小时内" + }, + "DaysLess": { + "One": "{param} 天内" + }, + "Export": { + "One": "导出" + }, + "AddToAddressBook": { + "One": "添加到地址簿" + }, + "BatchDelete": { + "One": "批量删除" + }, + "PleaseSelectData": { + "One": "请选择数据" } } diff --git a/src/utils/time.js b/src/utils/time.js new file mode 100644 index 0000000..c06cdcf --- /dev/null +++ b/src/utils/time.js @@ -0,0 +1,25 @@ +import { T } from '@/utils/i18n' + +export function timeAgo (time) { + let now = new Date().getTime() + let after = new Date(time).getTime() + let dis = now - after + if (dis < 60 * 1000) { + return T('JustNow') + } else if (dis < 60 * 60 * 1000) { + const num = Math.floor(dis / (60 * 1000)) + return T('MinutesAgo', { param: num }, num) + } else if (dis < 24 * 60 * 60 * 1000) { + const num = Math.floor(dis / (60 * 60 * 1000)) + return T('HoursAgo', { param: num }, num) + } else if (dis < 30 * 24 * 60 * 60 * 1000) { + const num = Math.floor(dis / (24 * 60 * 60 * 1000)) + return T('DaysAgo', { param: num }, num) + } else if (dis < 12 * 30 * 24 * 60 * 60 * 1000) { + const num = Math.floor(dis / (30 * 24 * 60 * 60 * 1000)) + return T('MonthsAgo', { param: num }, num) + } else { + const num = Math.floor(dis / (12 * 30 * 24 * 60 * 60 * 1000)) + return T('YearsAgo', { param: num }, num) + } +} diff --git a/src/views/address_book/index.js b/src/views/address_book/index.js index 427eba7..2fcbed1 100644 --- a/src/views/address_book/index.js +++ b/src/views/address_book/index.js @@ -1,13 +1,9 @@ import { reactive, ref } from 'vue' import { create, list, remove, update } from '@/api/address_book' import { ElMessage, ElMessageBox } from 'element-plus' -import { useRoute } from 'vue-router' import { T } from '@/utils/i18n' -export function useRepositories () { - const route = useRoute() - const user_id = route.query?.user_id - +export function useRepositories (user_id) { const listRes = reactive({ list: [], total: 0, loading: false, }) @@ -15,7 +11,10 @@ export function useRepositories () { page: 1, page_size: 10, is_my: 0, - user_id: user_id ? parseInt(user_id) : null, + id: null, + user_id: null, + username: null, + hostname: null, }) const getList = async () => { @@ -75,6 +74,7 @@ export function useRepositories () { 'sameServer': false, 'tags': [], 'user_id': null, + user_ids: [], 'username': '', }) diff --git a/src/views/address_book/index.vue b/src/views/address_book/index.vue index ea7b791..7cc5a0e 100644 --- a/src/views/address_book/index.vue +++ b/src/views/address_book/index.vue @@ -12,6 +12,15 @@ > + + + + + + + + + {{ T('Filter') }} {{ T('Add') }} @@ -80,12 +89,12 @@ - - - - - - + { @@ -167,10 +178,13 @@ toEdit, toAdd, submit, - activeChange, currentColor, } = useRepositories() + if (route.query?.user_id) { + listQuery.user_id = parseInt(route.query.user_id) + } + onMounted(getList) onActivated(getList) diff --git a/src/views/my/address_book/index.vue b/src/views/my/address_book/index.vue index d573ed4..70f414e 100644 --- a/src/views/my/address_book/index.vue +++ b/src/views/my/address_book/index.vue @@ -2,6 +2,15 @@
+ + + + + + + + + {{ T('Filter') }} {{ T('Add') }} @@ -55,12 +64,12 @@ - - - - - - + + diff --git a/src/views/tag/index.js b/src/views/tag/index.js index 1f7ac6d..9078f75 100644 --- a/src/views/tag/index.js +++ b/src/views/tag/index.js @@ -22,6 +22,10 @@ export function useRepositories () { // color 是十进制的数字,先转成16进制 let hex = color.toString(16) console.log('hex', hex) + if (hex.length < 8) { + //前面补0 + hex = '0'.repeat(8 - hex.length) + hex + } //前两位是透明度 let alpha = hex.slice(0, 2) //后六位是颜色 @@ -51,6 +55,7 @@ export function useRepositories () { if (b.length === 1) { b = '0' + b } + console.log('to f color', alpha + r + g + b, parseInt(alpha + r + g + b, 16)) return parseInt(alpha + r + g + b, 16) }