@gx-design-vue/create-gx-cli 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -11
- package/package.json +3 -2
- package/template-mobile-vant-cli/.editorconfig +19 -0
- package/template-mobile-vant-cli/.env +0 -0
- package/template-mobile-vant-cli/.env.development +19 -0
- package/template-mobile-vant-cli/.env.pro +19 -0
- package/template-mobile-vant-cli/.env.production +19 -0
- package/template-mobile-vant-cli/.eslintignore +15 -0
- package/template-mobile-vant-cli/.prettierignore +9 -0
- package/template-mobile-vant-cli/build/cdn.ts +5 -0
- package/template-mobile-vant-cli/build/generateModifyVars.ts +7 -0
- package/template-mobile-vant-cli/build/optimizer.ts +18 -0
- package/template-mobile-vant-cli/build/plugin/autoImport.ts +24 -0
- package/template-mobile-vant-cli/build/plugin/html.ts +26 -0
- package/template-mobile-vant-cli/build/plugin/index.ts +42 -0
- package/template-mobile-vant-cli/build/plugin/mock.ts +14 -0
- package/template-mobile-vant-cli/build/plugin/viteMock/client.ts +88 -0
- package/template-mobile-vant-cli/build/plugin/viteMock/createMockServer.ts +271 -0
- package/template-mobile-vant-cli/build/plugin/viteMock/index.ts +69 -0
- package/template-mobile-vant-cli/build/plugin/viteMock/types.ts +48 -0
- package/template-mobile-vant-cli/build/plugin/viteMock/utils.ts +48 -0
- package/template-mobile-vant-cli/build/script/postBuild.ts +14 -0
- package/template-mobile-vant-cli/eslint.config.js +49 -0
- package/template-mobile-vant-cli/index.html +24 -0
- package/template-mobile-vant-cli/mock/_createProductionServer.ts +19 -0
- package/template-mobile-vant-cli/mock/datasSource/api/index.ts +0 -0
- package/template-mobile-vant-cli/mock/utils.ts +9 -0
- package/template-mobile-vant-cli/package.json +57 -0
- package/template-mobile-vant-cli/postcss.config.cjs +8 -0
- package/template-mobile-vant-cli/prettier.config.cjs +18 -0
- package/template-mobile-vant-cli/public/favicon.ico +0 -0
- package/template-mobile-vant-cli/public/js/flexible.js +44 -0
- package/template-mobile-vant-cli/src/App.vue +5 -0
- package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +29 -0
- package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +115 -0
- package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +14 -0
- package/template-mobile-vant-cli/src/core/gx-design/index.ts +7 -0
- package/template-mobile-vant-cli/src/core/index.ts +12 -0
- package/template-mobile-vant-cli/src/core/vant-design/index.ts +4 -0
- package/template-mobile-vant-cli/src/design/config.less +0 -0
- package/template-mobile-vant-cli/src/design/index.less +3 -0
- package/template-mobile-vant-cli/src/design/reset.less +155 -0
- package/template-mobile-vant-cli/src/design/root.less +3 -0
- package/template-mobile-vant-cli/src/design/vant.less +2 -0
- package/template-mobile-vant-cli/src/global.less +1 -0
- package/template-mobile-vant-cli/src/hooks/web/index.ts +5 -0
- package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +58 -0
- package/template-mobile-vant-cli/src/layout/BasicLayout.vue +16 -0
- package/template-mobile-vant-cli/src/layout/basicLayout.less +11 -0
- package/template-mobile-vant-cli/src/main.ts +27 -0
- package/template-mobile-vant-cli/src/pages/home.vue +71 -0
- package/template-mobile-vant-cli/src/router/index.ts +25 -0
- package/template-mobile-vant-cli/src/router/routes.ts +20 -0
- package/template-mobile-vant-cli/src/router/typings.ts +8 -0
- package/template-mobile-vant-cli/src/services/index.ts +31 -0
- package/template-mobile-vant-cli/src/settings/index.ts +10 -0
- package/template-mobile-vant-cli/src/store/index.ts +17 -0
- package/template-mobile-vant-cli/src/store/modules/global.ts +30 -0
- package/template-mobile-vant-cli/src/utils/crypto/base64.ts +101 -0
- package/template-mobile-vant-cli/src/utils/crypto/index.ts +57 -0
- package/template-mobile-vant-cli/src/utils/env.ts +50 -0
- package/template-mobile-vant-cli/src/utils/pageTitle.ts +14 -0
- package/template-mobile-vant-cli/src/utils/request/XHR.ts +139 -0
- package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +69 -0
- package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +9 -0
- package/template-mobile-vant-cli/src/utils/request/index.ts +142 -0
- package/template-mobile-vant-cli/src/utils/request/typings.ts +171 -0
- package/template-mobile-vant-cli/src/utils/storage.ts +198 -0
- package/template-mobile-vant-cli/src/utils/util.ts +27 -0
- package/template-mobile-vant-cli/src/utils/validate.ts +216 -0
- package/template-mobile-vant-cli/tsconfig.json +42 -0
- package/template-mobile-vant-cli/types/ant-design-import.d.ts +13 -0
- package/template-mobile-vant-cli/types/auto-imports.d.ts +64 -0
- package/template-mobile-vant-cli/types/components.d.ts +12 -0
- package/template-mobile-vant-cli/types/global.d.ts +39 -0
- package/template-mobile-vant-cli/types/module.d.ts +20 -0
- package/template-mobile-vant-cli/types/plugins-auto-import.d.ts +14 -0
- package/template-mobile-vant-cli/types/response.d.ts +15 -0
- package/template-mobile-vant-cli/types/vant-import.d.ts +13 -0
- package/template-mobile-vant-cli/unocss.config.ts +101 -0
- package/template-mobile-vant-cli/vite.config.ts +145 -0
- package/template-mobile-vant-html/css/global.css +293 -0
- package/template-mobile-vant-html/css/global.css.map +1 -0
- package/template-mobile-vant-html/css/global.less +293 -0
- package/template-mobile-vant-html/css/index.css +20 -0
- package/template-mobile-vant-html/css/index.css.map +1 -0
- package/template-mobile-vant-html/css/index.less +21 -0
- package/template-mobile-vant-html/image/disconnected.svg +60 -0
- package/template-mobile-vant-html/image/empty.svg +52 -0
- package/template-mobile-vant-html/image/error.svg +53 -0
- package/template-mobile-vant-html/image/loading.svg +1 -0
- package/template-mobile-vant-html/index.html +91 -0
- package/template-mobile-vant-html/js/index.js +29 -0
- package/template-mobile-vant-html/js/plugin/day.min.js +1 -0
- package/template-mobile-vant-html/js/plugin/fastclick.js +730 -0
- package/template-mobile-vant-html/js/plugin/jquery.min.js +2 -0
- package/template-mobile-vant-html/js/plugin/rem.js +28 -0
- package/template-mobile-vant-html/js/utils/appUtil.js +70 -0
- package/template-mobile-vant-html/js/utils/config.js +3 -0
- package/template-mobile-vant-html/js/utils/request.js +61 -0
- package/template-mobile-vant-html/js/utils/utils.js +65 -0
- package/template-mobile-vant-html/js/utils/validate.js +292 -0
@@ -0,0 +1,155 @@
|
|
1
|
+
/****reset****/
|
2
|
+
body,
|
3
|
+
div,
|
4
|
+
table,
|
5
|
+
tr,
|
6
|
+
td,
|
7
|
+
th,
|
8
|
+
h1,
|
9
|
+
h2,
|
10
|
+
h3,
|
11
|
+
h4,
|
12
|
+
h5,
|
13
|
+
h6,
|
14
|
+
form,
|
15
|
+
input,
|
16
|
+
button,
|
17
|
+
label,
|
18
|
+
select,
|
19
|
+
textarea,
|
20
|
+
p,
|
21
|
+
u,
|
22
|
+
i,
|
23
|
+
em,
|
24
|
+
ul,
|
25
|
+
ol,
|
26
|
+
li,
|
27
|
+
dl,
|
28
|
+
dd,
|
29
|
+
dt,
|
30
|
+
img,
|
31
|
+
article,
|
32
|
+
aside,
|
33
|
+
details,
|
34
|
+
figcaption,
|
35
|
+
figure,
|
36
|
+
footer,
|
37
|
+
header,
|
38
|
+
menu,
|
39
|
+
nav,
|
40
|
+
section,
|
41
|
+
pre {
|
42
|
+
box-sizing: border-box;
|
43
|
+
margin: 0;
|
44
|
+
padding: 0;
|
45
|
+
font-size: 100%;
|
46
|
+
vertical-align: baseline;
|
47
|
+
border: 0;
|
48
|
+
outline: 0;
|
49
|
+
}
|
50
|
+
|
51
|
+
li {
|
52
|
+
list-style: none;
|
53
|
+
}
|
54
|
+
|
55
|
+
h1,
|
56
|
+
h2,
|
57
|
+
h3,
|
58
|
+
h4,
|
59
|
+
h5,
|
60
|
+
h6 {
|
61
|
+
font-size: 100%;
|
62
|
+
}
|
63
|
+
|
64
|
+
table {
|
65
|
+
border-collapse: collapse;
|
66
|
+
border-spacing: 0;
|
67
|
+
width: 100%;
|
68
|
+
}
|
69
|
+
|
70
|
+
a,
|
71
|
+
input,
|
72
|
+
select,
|
73
|
+
textarea,
|
74
|
+
area,
|
75
|
+
button {
|
76
|
+
outline: none;
|
77
|
+
font-family: inherit;
|
78
|
+
font-size: inherit;
|
79
|
+
border: none;
|
80
|
+
background: none;
|
81
|
+
color: inherit;
|
82
|
+
}
|
83
|
+
|
84
|
+
a {
|
85
|
+
text-decoration: none;
|
86
|
+
}
|
87
|
+
|
88
|
+
a:hover {
|
89
|
+
text-decoration: none;
|
90
|
+
}
|
91
|
+
|
92
|
+
textarea {
|
93
|
+
overflow: auto;
|
94
|
+
resize: none;
|
95
|
+
}
|
96
|
+
|
97
|
+
input[type='button'],
|
98
|
+
input[type='submit'],
|
99
|
+
input[type='reset'] {
|
100
|
+
cursor: pointer;
|
101
|
+
-webkit-appearance: none;
|
102
|
+
}
|
103
|
+
|
104
|
+
html,
|
105
|
+
body {
|
106
|
+
overflow-x: hidden;
|
107
|
+
width: 100%;
|
108
|
+
height: 100%;
|
109
|
+
background: #ffffff;
|
110
|
+
}
|
111
|
+
|
112
|
+
* {
|
113
|
+
-webkit-overflow-scrolling: touch;
|
114
|
+
}
|
115
|
+
|
116
|
+
html {
|
117
|
+
-webkit-tap-highlight-color: transparent;
|
118
|
+
}
|
119
|
+
|
120
|
+
body {
|
121
|
+
text-align: left;
|
122
|
+
padding-bottom: constant(safe-area-inset-bottom);
|
123
|
+
padding-bottom: env(safe-area-inset-bottom);
|
124
|
+
|
125
|
+
#app {
|
126
|
+
height: 100%;
|
127
|
+
-webkit-font-smoothing: antialiased;
|
128
|
+
-moz-osx-font-smoothing: grayscale;
|
129
|
+
overflow-x: hidden;
|
130
|
+
box-sizing: border-box;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
.fl {
|
135
|
+
float: left;
|
136
|
+
}
|
137
|
+
|
138
|
+
.fr {
|
139
|
+
float: right;
|
140
|
+
}
|
141
|
+
|
142
|
+
.clearfix {
|
143
|
+
zoom: 1;
|
144
|
+
&::before,
|
145
|
+
&::after {
|
146
|
+
display: table;
|
147
|
+
content: ' ';
|
148
|
+
}
|
149
|
+
&::after {
|
150
|
+
clear: both;
|
151
|
+
height: 0;
|
152
|
+
font-size: 0;
|
153
|
+
visibility: hidden;
|
154
|
+
}
|
155
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
@import './design/index';
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import type { Ref } from 'vue'
|
2
|
+
import { ref, watch } from 'vue'
|
3
|
+
import { closeToast, showLoadingToast } from 'vant'
|
4
|
+
import type { PageLoadingTpe } from '@/components/PageContainer'
|
5
|
+
|
6
|
+
export interface SetLoadingParams<T> {
|
7
|
+
value: T;
|
8
|
+
type?: PageLoadingTpe;
|
9
|
+
message?: string
|
10
|
+
}
|
11
|
+
|
12
|
+
type ChangeLoadingFn<T> = ({ value, type, message }: SetLoadingParams<T>) => void
|
13
|
+
|
14
|
+
export default function usePageLoading<T, R = Ref<T>>({
|
15
|
+
defaultType,
|
16
|
+
defaultMessage,
|
17
|
+
defaultLoading
|
18
|
+
}: {
|
19
|
+
defaultType?: PageLoadingTpe;
|
20
|
+
defaultMessage?: string;
|
21
|
+
defaultLoading?: T | (() => T);
|
22
|
+
}): [ R, ChangeLoadingFn<T> ] {
|
23
|
+
const initValue: T = typeof defaultLoading === 'function' ? (defaultLoading as any)() : defaultLoading
|
24
|
+
|
25
|
+
const pageLoading = ref(initValue) as Ref<T>
|
26
|
+
|
27
|
+
const loadingMessage = ref(defaultMessage)
|
28
|
+
|
29
|
+
const loadingType = ref(defaultType)
|
30
|
+
|
31
|
+
watch(() => pageLoading.value, (val) => {
|
32
|
+
if (val) {
|
33
|
+
if (loadingType.value === 'toast') {
|
34
|
+
showLoadingToast({
|
35
|
+
duration: 0,
|
36
|
+
forbidClick: true,
|
37
|
+
message: loadingMessage.value || '加载中'
|
38
|
+
})
|
39
|
+
} else {
|
40
|
+
closeToast()
|
41
|
+
}
|
42
|
+
} else {
|
43
|
+
closeToast()
|
44
|
+
}
|
45
|
+
}, {
|
46
|
+
deep: true,
|
47
|
+
immediate: true
|
48
|
+
})
|
49
|
+
|
50
|
+
const changeLoading = ({ value, type, message }: SetLoadingParams<T>) => {
|
51
|
+
pageLoading.value = value
|
52
|
+
loadingMessage.value = message
|
53
|
+
if (type)
|
54
|
+
loadingType.value = type
|
55
|
+
}
|
56
|
+
|
57
|
+
return [ pageLoading as unknown as R, changeLoading ]
|
58
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<script setup lang="ts">
|
2
|
+
</script>
|
3
|
+
|
4
|
+
<template>
|
5
|
+
<div :class="$style['basic-layout']">
|
6
|
+
<RouterView>
|
7
|
+
<template #default="{ Component }">
|
8
|
+
<component :is="Component" />
|
9
|
+
</template>
|
10
|
+
</RouterView>
|
11
|
+
</div>
|
12
|
+
</template>
|
13
|
+
|
14
|
+
<style lang="less" module>
|
15
|
+
@import './basicLayout';
|
16
|
+
</style>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { createApp } from 'vue'
|
2
|
+
import { setupRouter } from '@/router'
|
3
|
+
import { setupStore } from './store'
|
4
|
+
import { setupGlobCommon } from './core'
|
5
|
+
import App from './App.vue'
|
6
|
+
|
7
|
+
import 'uno.css'
|
8
|
+
|
9
|
+
import 'vant/es/toast/style'
|
10
|
+
|
11
|
+
import './global.less'
|
12
|
+
|
13
|
+
function startApp() {
|
14
|
+
const app = createApp(App)
|
15
|
+
|
16
|
+
// 配置store
|
17
|
+
setupStore(app)
|
18
|
+
|
19
|
+
// 配置路由
|
20
|
+
setupRouter(app)
|
21
|
+
|
22
|
+
setupGlobCommon(app)
|
23
|
+
|
24
|
+
app.mount('#app')
|
25
|
+
}
|
26
|
+
|
27
|
+
startApp()
|
@@ -0,0 +1,71 @@
|
|
1
|
+
<script setup lang="ts">
|
2
|
+
import { isBoolean } from '@gx-design-vue/pro-utils'
|
3
|
+
|
4
|
+
const loading = ref(false)
|
5
|
+
const pageContainer = ref()
|
6
|
+
const loadingMsg = ref('加载中')
|
7
|
+
const hiddenSlot = ref(true)
|
8
|
+
|
9
|
+
const init = (val?: boolean) => {
|
10
|
+
loadingMsg.value = '加载中'
|
11
|
+
loading.value = true
|
12
|
+
|
13
|
+
if (isBoolean(val))
|
14
|
+
hiddenSlot.value = val
|
15
|
+
|
16
|
+
setTimeout(() => {
|
17
|
+
loading.value = false
|
18
|
+
}, 1000)
|
19
|
+
}
|
20
|
+
|
21
|
+
onMounted(() => {
|
22
|
+
init()
|
23
|
+
})
|
24
|
+
|
25
|
+
const changeLoading = (message: string) => {
|
26
|
+
loadingMsg.value = message
|
27
|
+
loading.value = true
|
28
|
+
hiddenSlot.value = false
|
29
|
+
|
30
|
+
setTimeout(() => {
|
31
|
+
loading.value = false
|
32
|
+
}, 1000)
|
33
|
+
}
|
34
|
+
|
35
|
+
const toggleLoading = (hiddenSlot: boolean, message?: string) => {
|
36
|
+
pageContainer.value?.toggleLoading({
|
37
|
+
value: true,
|
38
|
+
hiddenSlot,
|
39
|
+
message
|
40
|
+
})
|
41
|
+
|
42
|
+
setTimeout(() => {
|
43
|
+
pageContainer.value?.toggleLoading({
|
44
|
+
value: false,
|
45
|
+
hiddenSlot
|
46
|
+
})
|
47
|
+
}, 1000)
|
48
|
+
}
|
49
|
+
</script>
|
50
|
+
|
51
|
+
<template>
|
52
|
+
<g-pro-page-container
|
53
|
+
ref="pageContainer"
|
54
|
+
v-model:loading="loading"
|
55
|
+
:loadingMsg="loadingMsg"
|
56
|
+
:hiddenSlot="hiddenSlot"
|
57
|
+
>
|
58
|
+
<div style="display: flex;flex-direction: column;gap: 20px;">
|
59
|
+
<p>以下刷新只针对toast</p>
|
60
|
+
<van-button @click="init(true)">刷新(隐藏子组件)</van-button>
|
61
|
+
<van-button @click="init(false)">刷新(不隐藏子组件)</van-button>
|
62
|
+
<van-button @click="changeLoading('切换中')">切换loading提示语</van-button>
|
63
|
+
<van-button @click="toggleLoading(true)">刷新-调用方法-隐藏</van-button>
|
64
|
+
<van-button @click="toggleLoading(false)">刷新-调用方法-不隐藏</van-button>
|
65
|
+
<van-button @click="toggleLoading(false, '切换中')">刷新-调用方法-不隐藏-切换提示语</van-button>
|
66
|
+
</div>
|
67
|
+
</g-pro-page-container>
|
68
|
+
</template>
|
69
|
+
|
70
|
+
<style lang="less" scoped>
|
71
|
+
</style>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import type { App } from 'vue'
|
2
|
+
import type { RouteRecordRaw } from 'vue-router'
|
3
|
+
import { createRouter, createWebHashHistory } from 'vue-router'
|
4
|
+
import settings from '@/settings'
|
5
|
+
import getPageTitle from '@/utils/pageTitle'
|
6
|
+
import { constantRoutes } from './routes'
|
7
|
+
|
8
|
+
export const router = createRouter({
|
9
|
+
history: createWebHashHistory(),
|
10
|
+
routes: constantRoutes as unknown as RouteRecordRaw[]
|
11
|
+
})
|
12
|
+
|
13
|
+
const doRouterPermission = () => {
|
14
|
+
router.afterEach((to) => {
|
15
|
+
const { meta }: any = to
|
16
|
+
document.title = getPageTitle(settings.title, meta.title || '')
|
17
|
+
})
|
18
|
+
}
|
19
|
+
|
20
|
+
// 配置路由器
|
21
|
+
export function setupRouter(app: App<Element>) {
|
22
|
+
app.use(router)
|
23
|
+
|
24
|
+
doRouterPermission()
|
25
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import type { AppRouteModule } from './typings'
|
2
|
+
import BasicLayout from '@/layout/BasicLayout.vue'
|
3
|
+
|
4
|
+
export const constantRoutes: AppRouteModule[] = [
|
5
|
+
{
|
6
|
+
path: '/',
|
7
|
+
component: BasicLayout,
|
8
|
+
redirect: '/home',
|
9
|
+
children: [
|
10
|
+
{
|
11
|
+
path: '/home',
|
12
|
+
name: 'Home',
|
13
|
+
meta: {
|
14
|
+
title: '首页'
|
15
|
+
},
|
16
|
+
component: () => import('@/pages/home.vue')
|
17
|
+
}
|
18
|
+
]
|
19
|
+
}
|
20
|
+
]
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import request from '@/utils/request'
|
2
|
+
|
3
|
+
// get 请求
|
4
|
+
export function getMock(params) {
|
5
|
+
return request({
|
6
|
+
url: '/get/mock',
|
7
|
+
method: 'get',
|
8
|
+
isMock: true,
|
9
|
+
params
|
10
|
+
})
|
11
|
+
}
|
12
|
+
|
13
|
+
// post 请求
|
14
|
+
export function postMock(data) {
|
15
|
+
return request({
|
16
|
+
url: '/post/mock',
|
17
|
+
method: 'post',
|
18
|
+
isMock: true,
|
19
|
+
data
|
20
|
+
})
|
21
|
+
}
|
22
|
+
|
23
|
+
// formData 请求
|
24
|
+
export function formDataMock(data) {
|
25
|
+
return request({
|
26
|
+
url: '/formData/mock',
|
27
|
+
method: 'post',
|
28
|
+
isMock: true,
|
29
|
+
data
|
30
|
+
})
|
31
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { App } from 'vue'
|
2
|
+
import { createPinia } from 'pinia'
|
3
|
+
import { useStoreGlobal } from './modules/global'
|
4
|
+
|
5
|
+
export {
|
6
|
+
useStoreGlobal
|
7
|
+
}
|
8
|
+
|
9
|
+
export function useStore() {
|
10
|
+
return {
|
11
|
+
global: useStoreGlobal()
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
export function setupStore(app: App<Element>) {
|
16
|
+
app.use(createPinia())
|
17
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { reactive, toRefs } from 'vue'
|
2
|
+
import { defineStore } from 'pinia'
|
3
|
+
import { deepCopy } from '@gx-design-vue/pro-utils'
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @Author gx12358
|
7
|
+
* @DateTime 2022/1/11
|
8
|
+
* @lastTime 2022/1/11
|
9
|
+
* @description store-global 全局属性
|
10
|
+
*/
|
11
|
+
export interface GlobalState {
|
12
|
+
token?: string; // app token
|
13
|
+
}
|
14
|
+
|
15
|
+
type GlobalStateKey = keyof GlobalState
|
16
|
+
|
17
|
+
export const useStoreGlobal = defineStore('global', () => {
|
18
|
+
const state = reactive<GlobalState>({
|
19
|
+
token: ''
|
20
|
+
})
|
21
|
+
|
22
|
+
const setGlobalData: (params: Partial<Record<GlobalStateKey, GlobalState[GlobalStateKey]>>) => void = (params) => {
|
23
|
+
Object.assign(state, deepCopy(params))
|
24
|
+
}
|
25
|
+
|
26
|
+
return {
|
27
|
+
...toRefs(state),
|
28
|
+
setGlobalData
|
29
|
+
}
|
30
|
+
})
|
@@ -0,0 +1,101 @@
|
|
1
|
+
export default class Base64 {
|
2
|
+
_keyStr: string
|
3
|
+
|
4
|
+
constructor() {
|
5
|
+
this._keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
|
6
|
+
}
|
7
|
+
|
8
|
+
_utf8_encode(string: string) {
|
9
|
+
string = string.replace(/\r\n/g, '\n')
|
10
|
+
let utftext = ''
|
11
|
+
for (let n = 0; n < string.length; n++) {
|
12
|
+
const c = string.charCodeAt(n)
|
13
|
+
if (c < 128) {
|
14
|
+
utftext += String.fromCharCode(c)
|
15
|
+
} else if ((c > 127) && (c < 2048)) {
|
16
|
+
utftext += String.fromCharCode((c >> 6) | 192)
|
17
|
+
utftext += String.fromCharCode((c & 63) | 128)
|
18
|
+
} else {
|
19
|
+
utftext += String.fromCharCode((c >> 12) | 224)
|
20
|
+
utftext += String.fromCharCode(((c >> 6) & 63) | 128)
|
21
|
+
utftext += String.fromCharCode((c & 63) | 128)
|
22
|
+
}
|
23
|
+
}
|
24
|
+
return utftext
|
25
|
+
}
|
26
|
+
|
27
|
+
_utf8_decode(utftext: string) {
|
28
|
+
let string = ''
|
29
|
+
let i = 0
|
30
|
+
let c = 0
|
31
|
+
let c1 = 0
|
32
|
+
let c2 = 0
|
33
|
+
while (i < utftext.length) {
|
34
|
+
c = utftext.charCodeAt(i)
|
35
|
+
if (c < 128) {
|
36
|
+
string += String.fromCharCode(c)
|
37
|
+
i++
|
38
|
+
} else if ((c > 191) && (c < 224)) {
|
39
|
+
c1 = utftext.charCodeAt(i + 1)
|
40
|
+
string += String.fromCharCode(((c & 31) << 6) | (c1 & 63))
|
41
|
+
i += 2
|
42
|
+
} else {
|
43
|
+
c1 = utftext.charCodeAt(i + 1)
|
44
|
+
c2 = utftext.charCodeAt(i + 2)
|
45
|
+
string += String.fromCharCode(((c & 15) << 12) | ((c1 & 63) << 6) | (c2 & 63))
|
46
|
+
i += 3
|
47
|
+
}
|
48
|
+
}
|
49
|
+
return string
|
50
|
+
}
|
51
|
+
|
52
|
+
encode(input: string) {
|
53
|
+
let output = ''
|
54
|
+
let chr1, chr2, chr3, enc1, enc2, enc3, enc4
|
55
|
+
let i = 0
|
56
|
+
input = this._utf8_encode(input)
|
57
|
+
while (i < input.length) {
|
58
|
+
chr1 = input.charCodeAt(i++)
|
59
|
+
chr2 = input.charCodeAt(i++)
|
60
|
+
chr3 = input.charCodeAt(i++)
|
61
|
+
enc1 = chr1 >> 2
|
62
|
+
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4)
|
63
|
+
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6)
|
64
|
+
enc4 = chr3 & 63
|
65
|
+
if (Number.isNaN(chr2)) {
|
66
|
+
enc3 = enc4 = 64
|
67
|
+
} else if (Number.isNaN(chr3)) {
|
68
|
+
enc4 = 64
|
69
|
+
}
|
70
|
+
output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(
|
71
|
+
enc3) + this._keyStr.charAt(enc4)
|
72
|
+
}
|
73
|
+
return output
|
74
|
+
}
|
75
|
+
|
76
|
+
decode(input: string) {
|
77
|
+
let output = ''
|
78
|
+
let chr1, chr2, chr3
|
79
|
+
let enc1, enc2, enc3, enc4
|
80
|
+
let i = 0
|
81
|
+
input = input.replace(/[^A-Za-z0-9+/=]/g, '')
|
82
|
+
while (i < input.length) {
|
83
|
+
enc1 = this._keyStr.indexOf(input.charAt(i++))
|
84
|
+
enc2 = this._keyStr.indexOf(input.charAt(i++))
|
85
|
+
enc3 = this._keyStr.indexOf(input.charAt(i++))
|
86
|
+
enc4 = this._keyStr.indexOf(input.charAt(i++))
|
87
|
+
chr1 = (enc1 << 2) | (enc2 >> 4)
|
88
|
+
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2)
|
89
|
+
chr3 = ((enc3 & 3) << 6) | enc4
|
90
|
+
output = output + String.fromCharCode(chr1)
|
91
|
+
if (enc3 !== 64) {
|
92
|
+
output = output + String.fromCharCode(chr2)
|
93
|
+
}
|
94
|
+
if (enc4 !== 64) {
|
95
|
+
output = output + String.fromCharCode(chr3)
|
96
|
+
}
|
97
|
+
}
|
98
|
+
output = this._utf8_decode(output)
|
99
|
+
return output
|
100
|
+
}
|
101
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import 'crypto-js/enc-utf8'
|
2
|
+
import 'crypto-js/tripledes'
|
3
|
+
import 'crypto-js/sha1'
|
4
|
+
import * as CryptoJS from 'crypto-js/core'
|
5
|
+
import CryptoProJS from 'crypto-js'
|
6
|
+
import { isJSONStr } from '@/utils/validate'
|
7
|
+
import { isArray, isObject } from '@gx-design-vue/pro-utils'
|
8
|
+
|
9
|
+
const key = '1234123412ABCDEF' // 十六位十六进制数作为密钥
|
10
|
+
|
11
|
+
/**
|
12
|
+
* 登录密码加密
|
13
|
+
* @param password
|
14
|
+
* @returns {string}
|
15
|
+
*/
|
16
|
+
export const encodePassword = (password: string) => {
|
17
|
+
const key = CryptoProJS.enc.Utf8.parse('8QONwyJtHesysWpM')
|
18
|
+
const passwordENC = CryptoProJS.AES.encrypt(password, key, {
|
19
|
+
mode: CryptoProJS.mode.ECB,
|
20
|
+
padding: CryptoProJS.pad.Pkcs7
|
21
|
+
})
|
22
|
+
const encodePW = passwordENC.ciphertext.toString()
|
23
|
+
return encodePW
|
24
|
+
}
|
25
|
+
|
26
|
+
// 加密方法
|
27
|
+
export function Encrypt(word) {
|
28
|
+
let str: string | object = word
|
29
|
+
if (isObject(word) || isArray(word)) {
|
30
|
+
str = JSON.stringify(word)
|
31
|
+
}
|
32
|
+
const keyHex = CryptoJS.enc.Utf8.parse(key)
|
33
|
+
const ivHex = CryptoJS.enc.Utf8.parse(key)
|
34
|
+
const encrypted = CryptoJS.DES.encrypt(str, keyHex, {
|
35
|
+
iv: ivHex,
|
36
|
+
mode: CryptoJS.mode.CBC,
|
37
|
+
padding: CryptoJS.pad.Pkcs7
|
38
|
+
})
|
39
|
+
return CryptoJS.enc.Base64.stringify(encrypted.ciphertext)
|
40
|
+
}
|
41
|
+
|
42
|
+
// 解密方法
|
43
|
+
export function Decrypt(word) {
|
44
|
+
const keyHex = CryptoJS.enc.Utf8.parse(key)
|
45
|
+
const ivHex = CryptoJS.enc.Utf8.parse(key)
|
46
|
+
const decrypted = CryptoJS.DES.decrypt({
|
47
|
+
ciphertext: CryptoJS.enc.Base64.parse(word)
|
48
|
+
}, keyHex, {
|
49
|
+
iv: ivHex,
|
50
|
+
mode: CryptoJS.mode.CBC,
|
51
|
+
padding: CryptoJS.pad.Pkcs7
|
52
|
+
})
|
53
|
+
const decryptedStr = decrypted.toString(CryptoJS.enc.Utf8)
|
54
|
+
return isJSONStr(decryptedStr.toString())
|
55
|
+
? JSON.parse(decryptedStr.toString())
|
56
|
+
: decryptedStr.toString()
|
57
|
+
}
|