@gx-design-vue/create-gx-cli 0.1.19 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -4
- package/dist/index.js +36 -48
- package/package.json +5 -3
- package/template-mobile-vant-cli/.editorconfig +19 -0
- package/template-mobile-vant-cli/.env +3 -0
- package/template-mobile-vant-cli/.env.development +17 -0
- package/template-mobile-vant-cli/.env.pro +28 -0
- package/template-mobile-vant-cli/.env.production +31 -0
- package/template-mobile-vant-cli/.eslintignore +15 -0
- package/template-mobile-vant-cli/.prettierignore +9 -0
- package/template-mobile-vant-cli/README.md +1 -0
- package/template-mobile-vant-cli/commitlint.config.cjs +32 -0
- package/template-mobile-vant-cli/config/default/defaultSettings.ts +70 -0
- package/template-mobile-vant-cli/config/default/network.ts +10 -0
- package/template-mobile-vant-cli/config/default/proxy.ts +50 -0
- package/template-mobile-vant-cli/config/default/theme.ts +3 -0
- package/template-mobile-vant-cli/config/index.ts +11 -0
- package/template-mobile-vant-cli/eslint.config.js +58 -0
- package/template-mobile-vant-cli/index.html +25 -0
- package/template-mobile-vant-cli/internal/vite-config/generate/generateModifyVars.ts +7 -0
- package/template-mobile-vant-cli/internal/vite-config/rollupOptions/index.ts +22 -0
- package/template-mobile-vant-cli/internal/vite-config/util/hash.ts +17 -0
- package/template-mobile-vant-cli/internal/vite-config/util/index.ts +132 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/cdn.ts +65 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/optimizer.ts +26 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/appConfig.ts +91 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/autoImport.ts +28 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/compress.ts +31 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/html.ts +32 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/index.ts +74 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/visualizer.ts +14 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/viteNotice.ts +40 -0
- package/template-mobile-vant-cli/mock/config/permissions.ts +15 -0
- package/template-mobile-vant-cli/mock/config/user/id.ts +5 -0
- package/template-mobile-vant-cli/mock/config/user/index.ts +96 -0
- package/template-mobile-vant-cli/mock/index.ts +55 -0
- package/template-mobile-vant-cli/mock/routers/table/index.fake.ts +22 -0
- package/template-mobile-vant-cli/mock/routers/user/account.fake.ts +52 -0
- package/template-mobile-vant-cli/mock/routers/user/index.fake.ts +46 -0
- package/template-mobile-vant-cli/mock/utils/crypto.ts +21 -0
- package/template-mobile-vant-cli/mock/utils/table.ts +96 -0
- package/template-mobile-vant-cli/mock/utils/util.ts +91 -0
- package/template-mobile-vant-cli/package.json +74 -0
- package/template-mobile-vant-cli/public/css/default.css +54 -0
- package/template-mobile-vant-cli/public/favicon.ico +0 -0
- package/template-mobile-vant-cli/src/App.vue +8 -0
- package/template-mobile-vant-cli/src/assets/logo.png +0 -0
- package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +29 -0
- package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +207 -0
- package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +17 -0
- package/template-mobile-vant-cli/src/components/TabsMenu/index.vue +45 -0
- package/template-mobile-vant-cli/src/core/gx-design/index.ts +7 -0
- package/template-mobile-vant-cli/src/core/index.ts +5 -0
- package/template-mobile-vant-cli/src/design/color.less +1 -0
- package/template-mobile-vant-cli/src/design/config.less +5 -0
- package/template-mobile-vant-cli/src/design/index.less +3 -0
- package/template-mobile-vant-cli/src/design/mixin.less +65 -0
- package/template-mobile-vant-cli/src/design/reset.less +39 -0
- package/template-mobile-vant-cli/src/design/root.less +3 -0
- package/template-mobile-vant-cli/src/design/vant/index.less +0 -0
- package/template-mobile-vant-cli/src/hooks/web/index.ts +5 -0
- package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +56 -0
- package/template-mobile-vant-cli/src/layout/BasicLayout/index.vue +18 -0
- package/template-mobile-vant-cli/src/layout/BasicLayout/style.less +3 -0
- package/template-mobile-vant-cli/src/layout/UserLayout/index.vue +18 -0
- package/template-mobile-vant-cli/src/layout/UserLayout/style.module.less +36 -0
- package/template-mobile-vant-cli/src/main.ts +34 -0
- package/template-mobile-vant-cli/src/pages/Account/details.vue +13 -0
- package/template-mobile-vant-cli/src/pages/Account/index.vue +102 -0
- package/template-mobile-vant-cli/src/pages/Home/index.vue +71 -0
- package/template-mobile-vant-cli/src/pages/user/login/index.vue +76 -0
- package/template-mobile-vant-cli/src/plugins/dayjs/index.ts +3 -0
- package/template-mobile-vant-cli/src/plugins/index.ts +2 -0
- package/template-mobile-vant-cli/src/router/guard/index.ts +18 -0
- package/template-mobile-vant-cli/src/router/guard/permissions.ts +41 -0
- package/template-mobile-vant-cli/src/router/guard/stateGuard.ts +10 -0
- package/template-mobile-vant-cli/src/router/index.ts +31 -0
- package/template-mobile-vant-cli/src/router/routes/index.ts +46 -0
- package/template-mobile-vant-cli/src/router/routes/modules/dataSource.ts +32 -0
- package/template-mobile-vant-cli/src/services/index.ts +31 -0
- package/template-mobile-vant-cli/src/services/userCenter/account.ts +42 -0
- package/template-mobile-vant-cli/src/services/userCenter/index.ts +28 -0
- package/template-mobile-vant-cli/src/store/index.ts +20 -0
- package/template-mobile-vant-cli/src/store/modules/global.ts +23 -0
- package/template-mobile-vant-cli/src/store/modules/user.ts +107 -0
- package/template-mobile-vant-cli/src/utils/accessToken.ts +97 -0
- package/template-mobile-vant-cli/src/utils/crypto/index.ts +56 -0
- package/template-mobile-vant-cli/src/utils/env.ts +50 -0
- package/template-mobile-vant-cli/src/utils/pageTitle.ts +20 -0
- package/template-mobile-vant-cli/src/utils/request/XHR.ts +137 -0
- package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +69 -0
- package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +25 -0
- package/template-mobile-vant-cli/src/utils/request/index.ts +155 -0
- package/template-mobile-vant-cli/src/utils/request/typings.ts +171 -0
- package/template-mobile-vant-cli/src/utils/storage.ts +215 -0
- package/template-mobile-vant-cli/src/utils/util.ts +27 -0
- package/template-mobile-vant-cli/src/utils/validate.ts +211 -0
- package/template-mobile-vant-cli/tsconfig.json +50 -0
- package/template-mobile-vant-cli/types/auto-imports.d.ts +80 -0
- package/template-mobile-vant-cli/types/components.d.ts +7 -0
- package/template-mobile-vant-cli/types/config.d.ts +56 -0
- package/template-mobile-vant-cli/types/global.d.ts +80 -0
- package/template-mobile-vant-cli/types/mock.d.ts +34 -0
- package/template-mobile-vant-cli/types/module.d.ts +61 -0
- package/template-mobile-vant-cli/types/response.d.ts +17 -0
- package/template-mobile-vant-cli/types/system.d.ts +58 -0
- package/template-mobile-vant-cli/types/vant-import.d.ts +25 -0
- package/template-mobile-vant-cli/unocss.config.ts +161 -0
- package/template-mobile-vant-cli/vite.config.ts +142 -0
- package/template-mobile-vant-html/README.md +4 -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
- package/template-vite-project/.env +5 -0
- package/template-vite-project/.env.development +5 -0
- package/template-vite-project/.env.pro +5 -0
- package/template-vite-project/.env.production +5 -0
- package/template-vite-project/README.md +5 -0
- package/template-vite-project/_gitignore +24 -0
- package/template-vite-project/index.html +46 -0
- package/template-vite-project/internal/proxy/index.ts +47 -0
- package/template-vite-project/internal/vite/generate/generateModifyVars.ts +9 -0
- package/template-vite-project/internal/vite/rollupOptions/index.ts +18 -0
- package/template-vite-project/internal/vite/util/hash.ts +17 -0
- package/template-vite-project/internal/vite/util/index.ts +132 -0
- package/template-vite-project/internal/vite/vite/cdn.ts +65 -0
- package/template-vite-project/internal/vite/vite/plugin/appConfig.ts +91 -0
- package/template-vite-project/internal/vite/vite/plugin/autoImport.ts +28 -0
- package/template-vite-project/internal/vite/vite/plugin/compress.ts +31 -0
- package/template-vite-project/internal/vite/vite/plugin/html.ts +24 -0
- package/template-vite-project/internal/vite/vite/plugin/index.ts +72 -0
- package/template-vite-project/internal/vite/vite/plugin/visualizer.ts +14 -0
- package/template-vite-project/internal/vite/vite/plugin/viteNotice.ts +40 -0
- package/template-vite-project/node_modules/.bin/cross-env +21 -0
- package/template-vite-project/node_modules/.bin/cross-env-shell +21 -0
- package/template-vite-project/node_modules/.bin/esbuild +21 -0
- package/template-vite-project/node_modules/.bin/jiti +21 -0
- package/template-vite-project/node_modules/.bin/lessc +21 -0
- package/template-vite-project/node_modules/.bin/parser +21 -0
- package/template-vite-project/node_modules/.bin/rollup +21 -0
- package/template-vite-project/node_modules/.bin/terser +21 -0
- package/template-vite-project/node_modules/.bin/tsc +21 -0
- package/template-vite-project/node_modules/.bin/tsserver +21 -0
- package/template-vite-project/node_modules/.bin/vite +21 -0
- package/template-vite-project/node_modules/.bin/vue-tsc +21 -0
- package/template-vite-project/node_modules/.bin/yaml +21 -0
- package/template-vite-project/package.json +38 -0
- package/template-vite-project/public/css/index.css +89 -0
- package/template-vite-project/public/css/normalize.css +396 -0
- package/template-vite-project/public/vite.svg +1 -0
- package/template-vite-project/src/App.vue +30 -0
- package/template-vite-project/src/assets/vue.svg +1 -0
- package/template-vite-project/src/components/HelloWorld.vue +41 -0
- package/template-vite-project/src/design/config.less +0 -0
- package/template-vite-project/src/design/index.less +0 -0
- package/template-vite-project/src/main.ts +14 -0
- package/template-vite-project/src/utils/env.ts +50 -0
- package/template-vite-project/tsconfig.app.json +59 -0
- package/template-vite-project/tsconfig.json +7 -0
- package/template-vite-project/tsconfig.node.json +28 -0
- package/template-vite-project/types/global.d.ts +33 -0
- package/template-vite-project/unocss.config.ts +208 -0
- package/template-vite-project/vite.config.ts +88 -0
@@ -0,0 +1,102 @@
|
|
1
|
+
<script setup lang="ts">
|
2
|
+
import multiavatar from '@multiavatar/multiavatar/esm'
|
3
|
+
|
4
|
+
const { user } = useStore()
|
5
|
+
const router = useRouter()
|
6
|
+
|
7
|
+
const svgCode = multiavatar(user.userInfo.userId)
|
8
|
+
|
9
|
+
function toDetails() {
|
10
|
+
router.push('/account/detail')
|
11
|
+
}
|
12
|
+
</script>
|
13
|
+
|
14
|
+
<template>
|
15
|
+
<g-page-container wrapperClass="h-full" bg-color="transparent" style="height: calc(100vh - var(--van-tabbar-height));">
|
16
|
+
<div class="bg" />
|
17
|
+
<div class="flex-center pt-15 pb-30">
|
18
|
+
<img src="@/assets/logo.png" class="w-60" alt="">
|
19
|
+
</div>
|
20
|
+
<div class="card flex gap-20 p-20">
|
21
|
+
<div class="w-60 h-60 rd-50% overflow-hidden flex-shrink" v-html="svgCode" @click="toDetails" />
|
22
|
+
<div class="flex-main flex-col flex justify-between">
|
23
|
+
<div class="text-14 font-bold flex items-center gap-10">
|
24
|
+
<span @click="toDetails">{{ user.userInfo.nickName }}</span>
|
25
|
+
<van-tag color="#7232dd" class="!px-8 !text-10">会员</van-tag>
|
26
|
+
</div>
|
27
|
+
<div class="flex flex-col gap-2 text-12 text-hex-999">
|
28
|
+
<div class="text-hidden-1" @click="toDetails">{{ user.userInfo.remark }}</div>
|
29
|
+
<div flex gap-10 items-center>
|
30
|
+
<van-progress class="flex-main relative top-1.5" :percentage="50" stroke-width="4" :show-pivot="false" />
|
31
|
+
<span>5/10</span>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
</div>
|
36
|
+
<div class="card px-20 py-15">
|
37
|
+
<div class="card-item">
|
38
|
+
<span class="font-bold text-13">我的订单</span>
|
39
|
+
<van-icon class="text-hex-999 text-13" name="arrow" />
|
40
|
+
</div>
|
41
|
+
<div class="card-item">
|
42
|
+
<span class="font-bold text-13">我的地址</span>
|
43
|
+
<van-icon class="text-hex-999 text-13" name="arrow" />
|
44
|
+
</div>
|
45
|
+
</div>
|
46
|
+
</g-page-container>
|
47
|
+
</template>
|
48
|
+
|
49
|
+
<style scoped lang="less">
|
50
|
+
.card {
|
51
|
+
--at-apply: bg-hex-fff rd-6 overflow-hidden;
|
52
|
+
|
53
|
+
& +.card {
|
54
|
+
--at-apply: mt-20;
|
55
|
+
}
|
56
|
+
|
57
|
+
.card-item {
|
58
|
+
--at-apply: flex items-center justify-between bd-b-main pb-15;
|
59
|
+
|
60
|
+
& + .card-item {
|
61
|
+
--at-apply: pt-15;
|
62
|
+
}
|
63
|
+
|
64
|
+
&:last-child {
|
65
|
+
--at-apply: pb-0;
|
66
|
+
border-bottom: 0;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
.bg {
|
71
|
+
z-index: -1;
|
72
|
+
pointer-events: none;
|
73
|
+
position: fixed;
|
74
|
+
top: 0;
|
75
|
+
left: 0;
|
76
|
+
right: 0;
|
77
|
+
bottom: 0;
|
78
|
+
transform: scale(1.5);
|
79
|
+
opacity: 0.2;
|
80
|
+
filter: blur(69px);
|
81
|
+
will-change: transform;
|
82
|
+
animation-timeline: auto;
|
83
|
+
animation-range-start: normal;
|
84
|
+
animation-range-end: normal;
|
85
|
+
background: linear-gradient(135deg, rgb(114, 46, 209) 0%, rgb(22, 119, 255) 30%, rgb(245, 34, 45) 70%, rgb(19, 194, 194) 100%) 0% 0% / 200% 200%;
|
86
|
+
animation: 10s ease 0s infinite normal none running glow;
|
87
|
+
}
|
88
|
+
|
89
|
+
@keyframes glow {
|
90
|
+
0% {
|
91
|
+
background-position: 0px -100%;
|
92
|
+
}
|
93
|
+
|
94
|
+
50% {
|
95
|
+
background-position: 200% 50%;
|
96
|
+
}
|
97
|
+
|
98
|
+
100% {
|
99
|
+
background-position: 0px -100%;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
</style>
|
@@ -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
|
+
}, 200)
|
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-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-page-container>
|
68
|
+
</template>
|
69
|
+
|
70
|
+
<style lang="less" scoped>
|
71
|
+
</style>
|
@@ -0,0 +1,76 @@
|
|
1
|
+
<script setup lang="ts">
|
2
|
+
import { reactive } from 'vue'
|
3
|
+
|
4
|
+
interface UserState {
|
5
|
+
userName: string
|
6
|
+
password: string
|
7
|
+
}
|
8
|
+
|
9
|
+
const { user } = useStore()
|
10
|
+
const router = useRouter()
|
11
|
+
|
12
|
+
const loading = ref(false)
|
13
|
+
|
14
|
+
const userForm = reactive<UserState>({
|
15
|
+
userName: 'admin',
|
16
|
+
password: 'gx.design'
|
17
|
+
})
|
18
|
+
|
19
|
+
const userRules = reactive({
|
20
|
+
userName: [ { required: true, message: '用户名是必填项!' } ],
|
21
|
+
password: [ { required: true, message: '密码是必填项!' } ]
|
22
|
+
})
|
23
|
+
|
24
|
+
const handleSubmit = async () => {
|
25
|
+
const response = await user.userLogin(toRaw(userForm))
|
26
|
+
if (response) {
|
27
|
+
router.push({ path: '/' })
|
28
|
+
}
|
29
|
+
}
|
30
|
+
</script>
|
31
|
+
|
32
|
+
<template>
|
33
|
+
<div class="h-100vh w-full pt-150 px-30">
|
34
|
+
<div class="flex items-end justify-center gap-20">
|
35
|
+
<img class="h-38" src="@/assets/logo.png" alt="logo">
|
36
|
+
<div class="bg-gradient-[to_bottom,#AE3FF5,#6EC0F9] bg-gradient-linear bg-clip-text text-28 text-transparent font-bold">
|
37
|
+
Gx Vant Mobile
|
38
|
+
</div>
|
39
|
+
</div>
|
40
|
+
<div class="mt-40">
|
41
|
+
<van-form validate-trigger="onSubmit">
|
42
|
+
<van-cell-group inset class="!mx-0">
|
43
|
+
<van-field
|
44
|
+
v-model="userForm.userName"
|
45
|
+
:rules="userRules.userName"
|
46
|
+
name="userName"
|
47
|
+
placeholder="用户名: admin"
|
48
|
+
/>
|
49
|
+
<van-field
|
50
|
+
v-model="userForm.password"
|
51
|
+
type="password"
|
52
|
+
:rules="userRules.password"
|
53
|
+
name="password"
|
54
|
+
placeholder="密码: gx.design"
|
55
|
+
/>
|
56
|
+
</van-cell-group>
|
57
|
+
|
58
|
+
<div class="mt-24">
|
59
|
+
<van-button
|
60
|
+
:loading="loading"
|
61
|
+
type="primary"
|
62
|
+
native-type="submit"
|
63
|
+
block
|
64
|
+
size="small"
|
65
|
+
@click="handleSubmit"
|
66
|
+
>
|
67
|
+
登录
|
68
|
+
</van-button>
|
69
|
+
</div>
|
70
|
+
</van-form>
|
71
|
+
</div>
|
72
|
+
</div>
|
73
|
+
</template>
|
74
|
+
|
75
|
+
<style scoped lang="less">
|
76
|
+
</style>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import type { MenuDataItem } from '@gx-design-vue/pro-layout'
|
2
|
+
import type { Router } from 'vue-router'
|
3
|
+
import getPageTitle from '@/utils/pageTitle'
|
4
|
+
import { createPermissionGuard } from './permissions'
|
5
|
+
import { createStateGuard } from './stateGuard'
|
6
|
+
|
7
|
+
export function setupRouterGuard(router: Router) {
|
8
|
+
createPageGuard(router)
|
9
|
+
createPermissionGuard(router)
|
10
|
+
createStateGuard(router)
|
11
|
+
}
|
12
|
+
|
13
|
+
export function createPageGuard(router: Router) {
|
14
|
+
router.afterEach((to) => {
|
15
|
+
const { meta } = to as MenuDataItem
|
16
|
+
document.title = getPageTitle(meta?.title || '')
|
17
|
+
})
|
18
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import type { Router } from 'vue-router'
|
2
|
+
import { defaultSettings } from '@gx-config'
|
3
|
+
|
4
|
+
const { loginInterception, routesWhiteList } = defaultSettings.system
|
5
|
+
|
6
|
+
export function createPermissionGuard(router: Router) {
|
7
|
+
const userStore = useStoreUser()
|
8
|
+
|
9
|
+
router.beforeEach(async (to, _, next) => {
|
10
|
+
if (loginInterception) {
|
11
|
+
const token = userStore.accessToken
|
12
|
+
if (routesWhiteList.includes(to.path)) {
|
13
|
+
if (token) {
|
14
|
+
next({ path: '/', replace: true })
|
15
|
+
}
|
16
|
+
next()
|
17
|
+
return
|
18
|
+
}
|
19
|
+
if (!token) {
|
20
|
+
userStore.resetPermissions()
|
21
|
+
next({ path: '/user/login', replace: true })
|
22
|
+
return
|
23
|
+
}
|
24
|
+
|
25
|
+
const hasUserId = userStore.userInfo.userId
|
26
|
+
|
27
|
+
if (hasUserId) {
|
28
|
+
next()
|
29
|
+
return
|
30
|
+
}
|
31
|
+
|
32
|
+
const status = await userStore.checkUserPremission()
|
33
|
+
if (status !== 1) {
|
34
|
+
userStore.resetPermissions()
|
35
|
+
next({ path: '/user/login', replace: true })
|
36
|
+
return
|
37
|
+
}
|
38
|
+
}
|
39
|
+
next()
|
40
|
+
})
|
41
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import type { App } from 'vue'
|
2
|
+
import type { RouteRecordRaw } from 'vue-router'
|
3
|
+
import { defaultSettings } from '@gx-config'
|
4
|
+
import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
|
5
|
+
import { routerList } from './routes'
|
6
|
+
|
7
|
+
const { routerMode } = defaultSettings.system
|
8
|
+
|
9
|
+
function handleRouterMode() {
|
10
|
+
switch (routerMode) {
|
11
|
+
case 'hash':
|
12
|
+
return createWebHashHistory()
|
13
|
+
break
|
14
|
+
case 'browser':
|
15
|
+
return createWebHistory()
|
16
|
+
break
|
17
|
+
default:
|
18
|
+
return createWebHashHistory()
|
19
|
+
break
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
export const router = createRouter({
|
24
|
+
history: handleRouterMode(),
|
25
|
+
routes: routerList as unknown as RouteRecordRaw[]
|
26
|
+
})
|
27
|
+
|
28
|
+
// 配置路由器
|
29
|
+
export function setupRouter(app: App<Element>) {
|
30
|
+
app.use(router)
|
31
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import BasicLayout from '@/layout/BasicLayout/index.vue'
|
2
|
+
import UserLayout from '@/layout/UserLayout/index.vue'
|
3
|
+
|
4
|
+
// import.meta.globEager() 直接引入所有的模块 Vite 独有的功能
|
5
|
+
const modules = import.meta.glob('./modules/**/*.ts', { eager: true })
|
6
|
+
const routeModuleList: AppRouteModule[] = []
|
7
|
+
|
8
|
+
// 加入到路由集合中
|
9
|
+
Object.keys(modules).forEach((key) => {
|
10
|
+
const mod = (modules[key] as any).default || {}
|
11
|
+
const modList = Array.isArray(mod) ? [ ...mod ] : [ mod ]
|
12
|
+
routeModuleList.push(...modList)
|
13
|
+
})
|
14
|
+
|
15
|
+
export const notFoundRoute: AppRouteModule = {
|
16
|
+
path: '/:path(.*)*',
|
17
|
+
name: 'NotFound',
|
18
|
+
redirect: '/'
|
19
|
+
}
|
20
|
+
|
21
|
+
// 自定义路由
|
22
|
+
export const routerList: AppRouteModule[] = [
|
23
|
+
{
|
24
|
+
path: '/user',
|
25
|
+
component: UserLayout,
|
26
|
+
name: 'UserLayout',
|
27
|
+
redirect: '/user/login',
|
28
|
+
children: [
|
29
|
+
{
|
30
|
+
path: '/user/login',
|
31
|
+
name: 'Login',
|
32
|
+
meta: {
|
33
|
+
title: '登录'
|
34
|
+
},
|
35
|
+
component: () => import('@/pages/user/login/index.vue')
|
36
|
+
}
|
37
|
+
]
|
38
|
+
},
|
39
|
+
{
|
40
|
+
path: '/',
|
41
|
+
name: '首页',
|
42
|
+
component: BasicLayout,
|
43
|
+
children: routeModuleList
|
44
|
+
},
|
45
|
+
notFoundRoute
|
46
|
+
]
|
@@ -0,0 +1,32 @@
|
|
1
|
+
export default [
|
2
|
+
{
|
3
|
+
path: '/',
|
4
|
+
name: 'Home',
|
5
|
+
meta: {
|
6
|
+
name: '首页',
|
7
|
+
icon: 'wap-home-o',
|
8
|
+
isMenu: true
|
9
|
+
},
|
10
|
+
component: () => import('@/pages/Home/index.vue')
|
11
|
+
},
|
12
|
+
{
|
13
|
+
path: '/account',
|
14
|
+
name: 'Account',
|
15
|
+
meta: {
|
16
|
+
name: '我的',
|
17
|
+
title: '个人中心',
|
18
|
+
icon: 'user-o',
|
19
|
+
isMenu: true
|
20
|
+
},
|
21
|
+
component: () => import('@/pages/Account/index.vue')
|
22
|
+
},
|
23
|
+
{
|
24
|
+
path: '/account/detail',
|
25
|
+
name: 'AccountDetails',
|
26
|
+
meta: {
|
27
|
+
title: '账号详情',
|
28
|
+
menuSelectKey: 'Account'
|
29
|
+
},
|
30
|
+
component: () => import('@/pages/Account/details.vue')
|
31
|
+
}
|
32
|
+
] as AppRouteModule[]
|
@@ -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,42 @@
|
|
1
|
+
import request from '@/utils/request'
|
2
|
+
|
3
|
+
export function getUserInfo<T, D = undefined>() {
|
4
|
+
return request<T, D>({
|
5
|
+
url: '/user/queryUserDetail',
|
6
|
+
method: 'get',
|
7
|
+
isMock: true
|
8
|
+
})
|
9
|
+
}
|
10
|
+
|
11
|
+
export function getUserList() {
|
12
|
+
return request({
|
13
|
+
url: '/user/account/list',
|
14
|
+
method: 'get',
|
15
|
+
isMock: true
|
16
|
+
})
|
17
|
+
}
|
18
|
+
|
19
|
+
export function getAccountGroupList() {
|
20
|
+
return request({
|
21
|
+
url: '/user/account/group',
|
22
|
+
method: 'get',
|
23
|
+
isMock: true
|
24
|
+
})
|
25
|
+
}
|
26
|
+
|
27
|
+
export function getAccountCount() {
|
28
|
+
return request({
|
29
|
+
url: '/user/account/count',
|
30
|
+
method: 'get',
|
31
|
+
isMock: true
|
32
|
+
})
|
33
|
+
}
|
34
|
+
|
35
|
+
export function updateUserDetails(data) {
|
36
|
+
return request({
|
37
|
+
url: '/user/account/update',
|
38
|
+
method: 'post',
|
39
|
+
data,
|
40
|
+
isMock: true
|
41
|
+
})
|
42
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import request from '@/utils/request'
|
2
|
+
|
3
|
+
export * from './account'
|
4
|
+
|
5
|
+
export function login<T, D>(data) {
|
6
|
+
return request<T, D>({
|
7
|
+
url: '/user/login',
|
8
|
+
method: 'post',
|
9
|
+
data,
|
10
|
+
isMock: true
|
11
|
+
})
|
12
|
+
}
|
13
|
+
|
14
|
+
export function logout() {
|
15
|
+
return request({
|
16
|
+
url: '/user/logout',
|
17
|
+
method: 'get',
|
18
|
+
isMock: true
|
19
|
+
})
|
20
|
+
}
|
21
|
+
|
22
|
+
export function register() {
|
23
|
+
return request({
|
24
|
+
url: '/user/register',
|
25
|
+
method: 'post',
|
26
|
+
isMock: true
|
27
|
+
})
|
28
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import type { App } from 'vue'
|
2
|
+
import { createPinia } from 'pinia'
|
3
|
+
import { useStoreGlobal } from './modules/global'
|
4
|
+
import { useStoreUser } from './modules/user'
|
5
|
+
|
6
|
+
export {
|
7
|
+
useStoreGlobal,
|
8
|
+
useStoreUser,
|
9
|
+
}
|
10
|
+
|
11
|
+
export function useStore() {
|
12
|
+
return {
|
13
|
+
user: useStoreUser(),
|
14
|
+
global: useStoreGlobal()
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
export function setupStore(app: App<Element>) {
|
19
|
+
app.use(createPinia())
|
20
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { useReactiveState } from '@gx-design-vue/pro-hooks'
|
2
|
+
import { defineStore } from 'pinia'
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @Author gx12358
|
6
|
+
* @DateTime 2022/1/11
|
7
|
+
* @lastTime 2022/1/11
|
8
|
+
* @description store-global 全局属性
|
9
|
+
*/
|
10
|
+
export interface GlobalState {
|
11
|
+
disabledScrollTop: boolean;
|
12
|
+
}
|
13
|
+
|
14
|
+
export const useStoreGlobal = defineStore('global', () => {
|
15
|
+
const [ state, setValue ] = useReactiveState<GlobalState>({
|
16
|
+
disabledScrollTop: false
|
17
|
+
})
|
18
|
+
|
19
|
+
return {
|
20
|
+
...state,
|
21
|
+
setValue
|
22
|
+
}
|
23
|
+
})
|