From 507d51b96d714e34bf06a4de440858e543ce9f7b Mon Sep 17 00:00:00 2001 From: toesbieya <1647775459@qq.com> Date: Sun, 14 Jun 2020 10:35:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E5=B0=8F=E8=B0=83=E6=95=B4=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E7=BB=93=E6=9E=84=20=E4=BF=AE=E6=94=B9=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E5=AD=97=E7=AC=A6=E4=B8=B2substring=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E7=9A=84=E5=9C=B0=E6=96=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vue/public/index.html | 3 + vue/src/components/Charts/PieChart.vue | 3 +- vue/src/components/TinymceEditor/index.vue | 2 +- .../Sidebar/components/SidebarItem.vue | 98 ++++++++--------- vue/src/mixins/chart/index.js | 4 + .../{chartLogicMixin.js => chart/logic.js} | 0 .../{chartResizeMixin.js => chart/resize.js} | 0 vue/src/mixins/guide/base.js | 13 ++- vue/src/plugin/{ => webgl}/fluid/Material.js | 0 vue/src/plugin/{ => webgl}/fluid/Pointer.js | 0 vue/src/plugin/{ => webgl}/fluid/Program.js | 0 vue/src/plugin/{ => webgl}/fluid/config.js | 0 vue/src/plugin/{ => webgl}/fluid/factory.js | 0 vue/src/plugin/{ => webgl}/fluid/index.js | 0 vue/src/plugin/{ => webgl}/fluid/shader.js | 0 vue/src/plugin/{ => webgl}/fluid/util.js | 0 vue/src/router/index.js | 2 +- vue/src/store/modules/app.js | 2 +- vue/src/store/modules/message.js | 2 +- vue/src/store/modules/resource.js | 2 +- vue/src/store/modules/setting.js | 2 +- vue/src/store/modules/user.js | 2 +- vue/src/utils/index.js | 100 ++++-------------- vue/src/utils/math.js | 42 ++++++++ vue/src/utils/secret.js | 19 ++++ vue/src/utils/sessionStorage.js | 29 ----- vue/src/utils/{localStorage.js => storage.js} | 32 +++++- vue/src/views/app/login/index.vue | 4 +- vue/src/views/app/login/style.scss | 2 +- vue/src/views/example/cool/fluid.vue | 2 +- .../components/ImageCompressTest.vue | 2 +- .../index/components/DailyFinishOrderStat.vue | 3 +- .../index/components/DailyProfitStat.vue | 3 +- .../purchase/order/components/EditDialog.vue | 3 +- .../sell/order/components/EditDialog.vue | 3 +- .../sell/outbound/components/EditDialog.vue | 3 +- vue/src/views/stock/current/DetailDialog.vue | 3 +- vue/src/views/stock/current/index.vue | 3 +- .../views/system/monitor/components/Cpu.vue | 3 +- .../views/system/monitor/components/Jvm.vue | 3 +- .../system/monitor/components/Memory.vue | 3 +- vue/src/views/system/monitor/index.vue | 3 +- 42 files changed, 208 insertions(+), 192 deletions(-) create mode 100644 vue/src/mixins/chart/index.js rename vue/src/mixins/{chartLogicMixin.js => chart/logic.js} (100%) rename vue/src/mixins/{chartResizeMixin.js => chart/resize.js} (100%) rename vue/src/plugin/{ => webgl}/fluid/Material.js (100%) rename vue/src/plugin/{ => webgl}/fluid/Pointer.js (100%) rename vue/src/plugin/{ => webgl}/fluid/Program.js (100%) rename vue/src/plugin/{ => webgl}/fluid/config.js (100%) rename vue/src/plugin/{ => webgl}/fluid/factory.js (100%) rename vue/src/plugin/{ => webgl}/fluid/index.js (100%) rename vue/src/plugin/{ => webgl}/fluid/shader.js (100%) rename vue/src/plugin/{ => webgl}/fluid/util.js (100%) create mode 100644 vue/src/utils/math.js create mode 100644 vue/src/utils/secret.js delete mode 100644 vue/src/utils/sessionStorage.js rename vue/src/utils/{localStorage.js => storage.js} (61%) diff --git a/vue/public/index.html b/vue/public/index.html index 00f307e..ca56a33 100644 --- a/vue/public/index.html +++ b/vue/public/index.html @@ -2,6 +2,9 @@ + + + diff --git a/vue/src/components/Charts/PieChart.vue b/vue/src/components/Charts/PieChart.vue index 91df97f..e72a673 100644 --- a/vue/src/components/Charts/PieChart.vue +++ b/vue/src/components/Charts/PieChart.vue @@ -3,8 +3,7 @@ diff --git a/vue/src/mixins/chart/index.js b/vue/src/mixins/chart/index.js new file mode 100644 index 0000000..88c6c00 --- /dev/null +++ b/vue/src/mixins/chart/index.js @@ -0,0 +1,4 @@ +import logic from "./logic" +import resize from "./resize" + +export {logic, resize} diff --git a/vue/src/mixins/chartLogicMixin.js b/vue/src/mixins/chart/logic.js similarity index 100% rename from vue/src/mixins/chartLogicMixin.js rename to vue/src/mixins/chart/logic.js diff --git a/vue/src/mixins/chartResizeMixin.js b/vue/src/mixins/chart/resize.js similarity index 100% rename from vue/src/mixins/chartResizeMixin.js rename to vue/src/mixins/chart/resize.js diff --git a/vue/src/mixins/guide/base.js b/vue/src/mixins/guide/base.js index b869719..427cfb7 100644 --- a/vue/src/mixins/guide/base.js +++ b/vue/src/mixins/guide/base.js @@ -1,4 +1,15 @@ -import {delAllUrlParam, transformGuideSteps} from "@/utils" +import {delAllUrlParam} from "@/utils" + +//将引导步骤中函数的this绑定为组件实例 +function transformGuideSteps(instance, steps) { + steps.forEach(step => { + Object.keys(step).forEach(key => { + if (typeof step[key] === 'function') { + step[key] = step[key].bind(instance) + } + }) + }) +} export default { methods: { diff --git a/vue/src/plugin/fluid/Material.js b/vue/src/plugin/webgl/fluid/Material.js similarity index 100% rename from vue/src/plugin/fluid/Material.js rename to vue/src/plugin/webgl/fluid/Material.js diff --git a/vue/src/plugin/fluid/Pointer.js b/vue/src/plugin/webgl/fluid/Pointer.js similarity index 100% rename from vue/src/plugin/fluid/Pointer.js rename to vue/src/plugin/webgl/fluid/Pointer.js diff --git a/vue/src/plugin/fluid/Program.js b/vue/src/plugin/webgl/fluid/Program.js similarity index 100% rename from vue/src/plugin/fluid/Program.js rename to vue/src/plugin/webgl/fluid/Program.js diff --git a/vue/src/plugin/fluid/config.js b/vue/src/plugin/webgl/fluid/config.js similarity index 100% rename from vue/src/plugin/fluid/config.js rename to vue/src/plugin/webgl/fluid/config.js diff --git a/vue/src/plugin/fluid/factory.js b/vue/src/plugin/webgl/fluid/factory.js similarity index 100% rename from vue/src/plugin/fluid/factory.js rename to vue/src/plugin/webgl/fluid/factory.js diff --git a/vue/src/plugin/fluid/index.js b/vue/src/plugin/webgl/fluid/index.js similarity index 100% rename from vue/src/plugin/fluid/index.js rename to vue/src/plugin/webgl/fluid/index.js diff --git a/vue/src/plugin/fluid/shader.js b/vue/src/plugin/webgl/fluid/shader.js similarity index 100% rename from vue/src/plugin/fluid/shader.js rename to vue/src/plugin/webgl/fluid/shader.js diff --git a/vue/src/plugin/fluid/util.js b/vue/src/plugin/webgl/fluid/util.js similarity index 100% rename from vue/src/plugin/fluid/util.js rename to vue/src/plugin/webgl/fluid/util.js diff --git a/vue/src/router/index.js b/vue/src/router/index.js index 1e25a8d..24d0a96 100644 --- a/vue/src/router/index.js +++ b/vue/src/router/index.js @@ -15,7 +15,7 @@ import Vue from 'vue' import Router from 'vue-router' import store from "@/store" import NProgress from 'nprogress' -import {isUserExist} from "@/utils/sessionStorage" +import {isUserExist} from "@/utils/storage" import {auth, needAuth} from "@/utils/auth" import {getPageTitle, transformWhiteList, metaExtend} from './util' import {routerMode} from '@/config' diff --git a/vue/src/store/modules/app.js b/vue/src/store/modules/app.js index 5586b7b..662feeb 100644 --- a/vue/src/store/modules/app.js +++ b/vue/src/store/modules/app.js @@ -1,4 +1,4 @@ -import {getLocalPersonalSettings} from "@/utils/localStorage" +import {getLocalPersonalSettings} from "@/utils/storage" import {createMutations} from "@/utils" import {isMobile} from "@/utils/browser" diff --git a/vue/src/store/modules/message.js b/vue/src/store/modules/message.js index 4a5276b..9714d85 100644 --- a/vue/src/store/modules/message.js +++ b/vue/src/store/modules/message.js @@ -7,7 +7,7 @@ const state = { const mutations = createMutations(state) -const actions={ +const actions = { refresh({commit}) { search({page: 1, pageSize: 1, unread: true}) .then(({data}) => commit('unreadCount', data)) diff --git a/vue/src/store/modules/resource.js b/vue/src/store/modules/resource.js index 11ceb3b..aed2b0d 100644 --- a/vue/src/store/modules/resource.js +++ b/vue/src/store/modules/resource.js @@ -3,7 +3,7 @@ import constantRoutes from '@/router/constant' import authorityRoutes from '@/router/authority' import {needAuth} from "@/utils/auth" import {createTree} from "@/utils/tree" -import {getLocalResource, setLocalResource} from "@/utils/localStorage" +import {getLocalResource, setLocalResource} from "@/utils/storage" import {getResources} from "@/api/system/resource" import {isEmpty} from "@/utils" diff --git a/vue/src/store/modules/setting.js b/vue/src/store/modules/setting.js index 5fbfd1f..6c25ed6 100644 --- a/vue/src/store/modules/setting.js +++ b/vue/src/store/modules/setting.js @@ -3,7 +3,7 @@ * */ import {isEmpty} from "@/utils" -import {getLocalPersonalSettings, setLocalPersonalSettings} from "@/utils/localStorage" +import {getLocalPersonalSettings, setLocalPersonalSettings} from "@/utils/storage" const localSettings = getLocalPersonalSettings() diff --git a/vue/src/store/modules/user.js b/vue/src/store/modules/user.js index f8fbb17..5840e96 100644 --- a/vue/src/store/modules/user.js +++ b/vue/src/store/modules/user.js @@ -1,7 +1,7 @@ import {login, logout} from '@/api/account' import {createMutations, isEmpty} from "@/utils" import {autoCompleteUrl} from "@/utils/file" -import {getUser, setUser} from "@/utils/sessionStorage" +import {getUser, setUser} from "@/utils/storage" //刷新时从本地存储中获取用户信息 const user = getUser() diff --git a/vue/src/utils/index.js b/vue/src/utils/index.js index d012755..f8d044b 100644 --- a/vue/src/utils/index.js +++ b/vue/src/utils/index.js @@ -1,6 +1,3 @@ -import pako from 'pako' -import Decimal from 'decimal.js' - export function isEmpty(...str) { return str.some(i => i === undefined || i === null || i === '') } @@ -34,9 +31,10 @@ export function mergeObj(target, source) { }) } -export function timeFormat(fmt = 'yyyy-MM-dd HH:mm:ss', date = new Date()) { +export function timeFormat(fmt, date = new Date()) { if (isEmpty(fmt)) fmt = 'yyyy-MM-dd HH:mm:ss' - let o = { + + const o = { "M+": date.getMonth() + 1, //月份 "d+": date.getDate(), //日 "H+": date.getHours(), //小时 @@ -45,9 +43,20 @@ export function timeFormat(fmt = 'yyyy-MM-dd HH:mm:ss', date = new Date()) { "q+": Math.floor((date.getMonth() + 3) / 3), //季度 "S": date.getMilliseconds() //毫秒 } - if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)) - for (let k in o) - if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))) + + if (/(y+)/.test(fmt)) { + const replace = (date.getFullYear() + "").substring(4 - RegExp.$1.length) + fmt = fmt.replace(RegExp.$1, [...replace].join('')) + } + + for (let k in o) { + if (new RegExp(`(${k})`).test(fmt)) { + const firstMatch = RegExp.$1 + const replace = firstMatch.length === 1 ? o[k] : ("00" + o[k]).substring(("" + o[k]).length) + fmt = fmt.replace(firstMatch, [...replace].join('')) + } + } + return fmt } @@ -111,24 +120,6 @@ export function throttle(func, delay = 100) { return wrapper } -export function unzip(b64Data) { - let strData = atob(b64Data) - // Convert binary string to character-number array - let charData = strData.split('').map(x => x.charCodeAt(0)) - // Turn number array into byte-array - let binData = new Uint8Array(charData) - // unzip - let data = pako.inflate(binData) - // Convert gunzipped byteArray back to ascii string: - strData = String.fromCharCode.apply(null, new Uint16Array(data)) - return decodeURIComponent(strData) -} - -export function zip(str) { - let binaryString = pako.gzip(encodeURIComponent(str), {to: 'string'}) - return btoa(binaryString) -} - /** * 循环等待成功事件 * @param success 判断是否成功,true or false @@ -170,68 +161,15 @@ export function createMutations(state, all = false) { return obj } -//将引导步骤中函数的this绑定为组件实例 -export function transformGuideSteps(instance, steps) { - steps.forEach(step => { - Object.keys(step).forEach(key => { - if (typeof step[key] === 'function') { - step[key] = step[key].bind(instance) - } - }) - }) -} - //删除所有url参数 export function delAllUrlParam() { let paramStartIndex = location.href.indexOf('?') if (paramStartIndex > -1) { - history.replaceState(null, null, location.href.substring(0, paramStartIndex)) - } -} - - -/*基于decimal.js的运算封装*/ -export function plus(...val) { - if (val.length === 0) return 0 - else if (val.length === 1) return new Decimal(val[0]).toNumber() - let f = new Decimal(val[0]) - for (let i = 1; i < val.length; i++) { - f = f.add(new Decimal(val[i])) - } - return f.toNumber() -} - -export function sub(...val) { - if (val.length === 0) return 0 - else if (val.length === 1) return new Decimal(val[0]).toNumber() - let f = new Decimal(val[0]) - for (let i = 1; i < val.length; i++) { - f = f.sub(new Decimal(val[i])) + const href = location.href.substring(0, paramStartIndex) + history.replaceState(null, null, [...href].join('')) } - return f.toNumber() } -export function mul(...val) { - if (val.length === 0) return 0 - else if (val.length === 1) return new Decimal(val[0]).toNumber() - let f = new Decimal(val[0]) - for (let i = 1; i < val.length; i++) { - f = f.mul(new Decimal(val[i])) - } - return f.toNumber() -} - -export function div(...val) { - if (val.length === 0) return 0 - else if (val.length === 1) return new Decimal(val[0]).toNumber() - let f = new Decimal(val[0]) - for (let i = 1; i < val.length; i++) { - f = f.div(new Decimal(val[i])) - } - return f.toNumber() -} - - export function deepClone(data) { if (data === null || data === undefined) { return undefined diff --git a/vue/src/utils/math.js b/vue/src/utils/math.js new file mode 100644 index 0000000..501d87e --- /dev/null +++ b/vue/src/utils/math.js @@ -0,0 +1,42 @@ +import Decimal from 'decimal.js' + +/*基于decimal.js的运算封装*/ +export function plus(...val) { + if (val.length === 0) return 0 + else if (val.length === 1) return new Decimal(val[0]).toNumber() + let f = new Decimal(val[0]) + for (let i = 1; i < val.length; i++) { + f = f.add(new Decimal(val[i])) + } + return f.toNumber() +} + +export function sub(...val) { + if (val.length === 0) return 0 + else if (val.length === 1) return new Decimal(val[0]).toNumber() + let f = new Decimal(val[0]) + for (let i = 1; i < val.length; i++) { + f = f.sub(new Decimal(val[i])) + } + return f.toNumber() +} + +export function mul(...val) { + if (val.length === 0) return 0 + else if (val.length === 1) return new Decimal(val[0]).toNumber() + let f = new Decimal(val[0]) + for (let i = 1; i < val.length; i++) { + f = f.mul(new Decimal(val[i])) + } + return f.toNumber() +} + +export function div(...val) { + if (val.length === 0) return 0 + else if (val.length === 1) return new Decimal(val[0]).toNumber() + let f = new Decimal(val[0]) + for (let i = 1; i < val.length; i++) { + f = f.div(new Decimal(val[i])) + } + return f.toNumber() +} diff --git a/vue/src/utils/secret.js b/vue/src/utils/secret.js new file mode 100644 index 0000000..ec8fe08 --- /dev/null +++ b/vue/src/utils/secret.js @@ -0,0 +1,19 @@ +import pako from 'pako' + +export function unzip(b64Data) { + let strData = atob(b64Data) + // Convert binary string to character-number array + let charData = strData.split('').map(x => x.charCodeAt(0)) + // Turn number array into byte-array + let binData = new Uint8Array(charData) + // unzip + let data = pako.inflate(binData) + // Convert gunzipped byteArray back to ascii string: + strData = String.fromCharCode.apply(null, new Uint16Array(data)) + return decodeURIComponent(strData) +} + +export function zip(str) { + let binaryString = pako.gzip(encodeURIComponent(str), {to: 'string'}) + return btoa(binaryString) +} diff --git a/vue/src/utils/sessionStorage.js b/vue/src/utils/sessionStorage.js deleted file mode 100644 index 9648117..0000000 --- a/vue/src/utils/sessionStorage.js +++ /dev/null @@ -1,29 +0,0 @@ -import {sessionUserKey} from '@/config' -import {isEmpty, unzip, zip} from "@/utils" - -export function isUserExist() { - return !isEmpty(sessionStorage.getItem(sessionUserKey)) -} - -export function getUser() { - let obj = sessionStorage.getItem(sessionUserKey) - if (isEmpty(obj)) return {} - try { - obj = JSON.parse(unzip(obj)) - } - catch (e) { - console.error('用户数据异常!', e) - obj = {} - removeUser() - } - return obj -} - -export function setUser(user) { - if (isEmpty(user)) return removeUser() - sessionStorage.setItem(sessionUserKey, zip(JSON.stringify(user))) -} - -function removeUser() { - sessionStorage.removeItem(sessionUserKey) -} diff --git a/vue/src/utils/localStorage.js b/vue/src/utils/storage.js similarity index 61% rename from vue/src/utils/localStorage.js rename to vue/src/utils/storage.js index e5bb6ef..0a9f416 100644 --- a/vue/src/utils/localStorage.js +++ b/vue/src/utils/storage.js @@ -1,5 +1,29 @@ -import {localPersonalSettingsKey, localResourceKey} from '@/config' -import {isEmpty, unzip, zip} from "@/utils" +import {sessionUserKey, localPersonalSettingsKey, localResourceKey} from '@/config' +import {isEmpty} from "@/utils" +import {unzip, zip} from "@/utils/secret" + +export function isUserExist() { + return !isEmpty(sessionStorage.getItem(sessionUserKey)) +} + +export function getUser() { + let obj = sessionStorage.getItem(sessionUserKey) + if (isEmpty(obj)) return {} + try { + obj = JSON.parse(unzip(obj)) + } + catch (e) { + console.error('用户数据异常!', e) + obj = {} + removeUser() + } + return obj +} + +export function setUser(user) { + if (isEmpty(user)) return removeUser() + sessionStorage.setItem(sessionUserKey, zip(JSON.stringify(user))) +} export function getLocalResource() { let obj = localStorage.getItem(localResourceKey) @@ -41,6 +65,10 @@ export function setLocalPersonalSettings(settings) { localStorage.setItem(localPersonalSettingsKey, JSON.stringify(settings)) } +function removeUser() { + sessionStorage.removeItem(sessionUserKey) +} + function removeLocalResource() { localStorage.removeItem(localResourceKey) } diff --git a/vue/src/views/app/login/index.vue b/vue/src/views/app/login/index.vue index 3bd7f7a..88ef540 100644 --- a/vue/src/views/app/login/index.vue +++ b/vue/src/views/app/login/index.vue @@ -34,8 +34,8 @@ animation: state => state.loginBackgroundAnimation }), component() { - const {path} = this.$route - return `${path.substring(1)}-form` + const formType = this.$route.path.substring(1) + return `${[...formType].join('')}-form` } }, methods: { diff --git a/vue/src/views/app/login/style.scss b/vue/src/views/app/login/style.scss index e9939fc..a60c879 100644 --- a/vue/src/views/app/login/style.scss +++ b/vue/src/views/app/login/style.scss @@ -12,7 +12,7 @@ $cursor: #fff; .login-page { display: flex; flex-direction: column; - height: 100vh; + height: 100%; overflow: auto; canvas { diff --git a/vue/src/views/example/cool/fluid.vue b/vue/src/views/example/cool/fluid.vue index be1b5cf..57d3281 100644 --- a/vue/src/views/example/cool/fluid.vue +++ b/vue/src/views/example/cool/fluid.vue @@ -26,7 +26,7 @@ window.removeEventListener('resize', this.$_resizeHandler) }, start() { - import('@/plugin/fluid').then(_ => _.default(this.$el.querySelector('#canvas-fluid'))) + import('@/plugin/webgl/fluid').then(_ => _.default(this.$el.querySelector('#canvas-fluid'))) }, close() { window.location.reload() diff --git a/vue/src/views/example/developingTest/components/ImageCompressTest.vue b/vue/src/views/example/developingTest/components/ImageCompressTest.vue index 1c1659e..8244d4d 100644 --- a/vue/src/views/example/developingTest/components/ImageCompressTest.vue +++ b/vue/src/views/example/developingTest/components/ImageCompressTest.vue @@ -73,7 +73,7 @@ import {elError, elSuccess} from "@/utils/message" import compressJPG from '@/plugin/imageCompress/cjpeg' import compressPNG from '@/plugin/imageCompress/pngquant' - import {div, mul, sub} from "@/utils" + import {sub, mul, div} from "@/utils/math" const commonData = () => ({ loading: false, diff --git a/vue/src/views/index/components/DailyFinishOrderStat.vue b/vue/src/views/index/components/DailyFinishOrderStat.vue index cb7bf31..db61afb 100644 --- a/vue/src/views/index/components/DailyFinishOrderStat.vue +++ b/vue/src/views/index/components/DailyFinishOrderStat.vue @@ -3,8 +3,7 @@