@yyp92-cli/template-vue-mobile 1.2.1 → 1.4.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @yyp92-cli/template-vue-mobile
2
2
 
3
+ ## 1.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 路由修改
8
+
9
+ ## 1.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 项目模板-二级路由修改
14
+
3
15
  ## 1.2.1
4
16
 
5
17
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yyp92-cli/template-vue-mobile",
3
- "version": "1.2.1",
3
+ "version": "1.4.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -1,27 +1,24 @@
1
1
  <template>
2
2
  <div class="layout">
3
- <template v-if="route.meta.showFullScreen">
4
- <router-view></router-view>
5
- </template>
6
-
7
- <template v-else>
8
- <div class="layout-inner">
9
- <div class="header">
10
- <MyNavBar
11
- :title="title"
12
- :showLeftArrow="route.fullPath !== '/home'"
13
- />
14
- </div>
3
+ <div class="layout-inner">
4
+ <div class="header">
5
+ <MyNavBar
6
+ :title="title"
7
+ :showLeftArrow="route.fullPath !== '/home'"
8
+ />
9
+ </div>
15
10
 
16
- <div class="content">
17
- <router-view></router-view>
18
- </div>
11
+ <div class="content">
12
+ <router-view></router-view>
13
+ </div>
19
14
 
20
- <div class="footer">
21
- <MyTabBar />
22
- </div>
15
+ <div
16
+ class="footer"
17
+ v-if="!route.meta.showFullScreen"
18
+ >
19
+ <MyTabBar />
23
20
  </div>
24
- </template>
21
+ </div>
25
22
  </div>
26
23
  </template>
27
24
 
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <div class="tab-bar">
3
3
  <van-tabbar
4
- v-model="active"
4
+ v-model="defaultActive"
5
5
  >
6
6
  <template
7
7
  v-for="item in loginStore.userMenus"
@@ -21,18 +21,21 @@
21
21
  lang="ts"
22
22
  name="MyTabBar"
23
23
  >
24
- import {ref, onMounted} from 'vue'
24
+ import {computed} from 'vue'
25
25
  import {useRoute} from 'vue-router'
26
26
  import useLoginStore from '@/store/login'
27
27
 
28
28
  const route = useRoute()
29
29
  const loginStore = useLoginStore()
30
- const active = ref(0)
31
- console.log('--loginStore.userMenus', loginStore.userMenus)
32
30
 
33
- onMounted(() => {
34
- const index = loginStore.userMenus.findIndex((item: any) => item.path === route.path)
35
- active.value = index || 0
31
+
32
+ const defaultActive = computed(() => {
33
+ const list = route.path?.split('/')
34
+ const newPath = list.length > 3 ? list?.slice(0, 3)?.join('/') : route.path
35
+
36
+ const index = loginStore.userMenus.findIndex((item: any) => newPath.indexOf(item.path) > -1)
37
+
38
+ return index
36
39
  })
37
40
  </script>
38
41
 
@@ -20,26 +20,34 @@ router.beforeEach((to, from, next) => {
20
20
  const menus = localCache.getCache(MENUS) ?? []
21
21
  const token = localCache.getCache(LOGIN_TOKEN)
22
22
 
23
- if (to.path === '/') {
24
- if (!token) {
25
- next({
26
- path: '/login'
27
- })
28
- }
29
- else {
30
- next({
31
- path: menus[0]?.path || '/'
32
- })
23
+ if (!token) {
24
+ // 直接允许通过,不重复重定向
25
+ if (to.path === '/login') {
26
+ next()
27
+ return
33
28
  }
29
+
30
+ next({
31
+ path: '/login',
32
+ query: {
33
+ redirect: to.path
34
+ }
35
+ })
36
+ return
37
+ }
38
+ else if (to.path === '/') {
39
+ next({
40
+ path: menus[0]?.path || '/'
41
+ })
42
+ return
34
43
  }
35
44
  else if (!['/403', '/login'].includes(to.path) && !permission.includes(to.path) && getLocalPromission(routes).includes(to.path)) {
36
- return next('/403')
45
+ next('/403')
46
+ return
37
47
  }
38
48
  else {
39
49
  next()
40
50
  }
41
-
42
- next()
43
51
  })
44
52
 
45
53
  export default router
@@ -50,13 +50,24 @@ export const routes: any[] = [
50
50
  }
51
51
  },
52
52
  {
53
- path: '/detail',
54
- name: 'detail',
55
- component: () => import('@/views/detail/index.vue'),
53
+ path: '/home/detail',
54
+ name: '/home/detail',
55
+ component: () => import('@/views/home/detail/index.vue'),
56
56
  meta: {
57
57
  title: '详情',
58
58
  icon: '',
59
59
  hideMenu: true,
60
+ showFullScreen: false
61
+ }
62
+ },
63
+ {
64
+ path: '/home/screen-detail',
65
+ name: '/home/screen-detail',
66
+ component: () => import('@/views/home/screen-detail/index.vue'),
67
+ meta: {
68
+ title: '详情-全屏',
69
+ icon: '',
70
+ hideMenu: true,
60
71
  showFullScreen: true
61
72
  }
62
73
  },
@@ -23,14 +23,28 @@ const useLoginStore = defineStore(
23
23
  actions: {
24
24
  async loginAccountAction(account: any) {
25
25
  try {
26
- setTimeout(() => {
26
+ await new Promise((resolve) => {
27
+ const userInfo = {
28
+ username: account.username
29
+ }
30
+ const token = '111'
31
+ this.userInfo = userInfo
32
+ this.token = token
33
+
34
+ localCache.setCache(USER_INFO, userInfo)
35
+ localCache.setCache(LOGIN_TOKEN, token)
36
+
27
37
  const menus = routes[0].children.filter((item: any) => !item.meta.hideMenu)
28
38
  const promissions = routes[0].children.map((item: any) => item.path)
29
39
  this.userMenus = menus
30
40
 
31
41
  localCache.setCache(MENUS, menus)
32
42
  localCache.setCache(PERMISSION, promissions)
33
- }, 3000)
43
+
44
+ setTimeout(() => {
45
+ resolve(true)
46
+ }, 5000)
47
+ })
34
48
  }
35
49
  catch(error) {
36
50
  return error
@@ -1,6 +1,18 @@
1
1
  <template>
2
2
  <div class="home">
3
3
  <h2>home</h2>
4
+
5
+ <div>
6
+ <van-button
7
+ type="primary"
8
+ @click="handleJump"
9
+ >详情</van-button>
10
+
11
+ <van-button
12
+ type="primary"
13
+ @click="handleJump1"
14
+ >详情-全屏</van-button>
15
+ </div>
4
16
  </div>
5
17
  </template>
6
18
 
@@ -9,6 +21,17 @@
9
21
  lang="ts"
10
22
  name="Home"
11
23
  >
24
+ import {useRouter} from 'vue-router'
25
+
26
+ const router = useRouter()
27
+
28
+ function handleJump() {
29
+ router.push('/home/detail')
30
+ }
31
+
32
+ function handleJump1() {
33
+ router.push('/home/screen-detail')
34
+ }
12
35
  </script>
13
36
 
14
37
  <style
@@ -0,0 +1,19 @@
1
+ <template>
2
+ <div class="detail">
3
+ <h2>detail-screen</h2>
4
+ </div>
5
+ </template>
6
+
7
+ <script
8
+ setup
9
+ lang="ts"
10
+ name="Detail"
11
+ >
12
+ </script>
13
+
14
+ <style
15
+ scoped
16
+ lang="scss"
17
+ >
18
+ .detail {}
19
+ </style>
@@ -21,8 +21,13 @@
21
21
  </van-cell-group>
22
22
 
23
23
  <div style="margin: 16px;">
24
- <van-button round block type="primary" native-type="submit">
25
- 提交
24
+ <van-button
25
+ round
26
+ block
27
+ type="primary"
28
+ native-type="submit"
29
+ >
30
+ 提交
26
31
  </van-button>
27
32
  </div>
28
33
  </van-form>
@@ -36,8 +41,8 @@
36
41
  >
37
42
  import { ref } from 'vue'
38
43
  import {useRoute} from 'vue-router'
39
- import { showLoadingToast, closeToast } from 'vant'
40
44
  import useLoginStore from '@/store/login'
45
+
41
46
  import router from '@/router'
42
47
 
43
48
  const route = useRoute()
@@ -19,6 +19,8 @@
19
19
  "include": [
20
20
  "src/**/*.ts",
21
21
  "src/**/*.tsx",
22
- "src/**/*.vue"
22
+ "src/**/*.vue",
23
+ "src/**/*.d.ts", // 关键:包含所有 .d.ts 类型文件
24
+ "auto-imports.d.ts"
23
25
  ]
24
26
  }
@@ -9,6 +9,7 @@ import Components from 'unplugin-vue-components/vite'
9
9
  import { VantResolver } from '@vant/auto-import-resolver'
10
10
 
11
11
 
12
+
12
13
  // https://vite.dev/config/
13
14
  export default defineConfig({
14
15
  base:'./',
@@ -31,10 +32,20 @@ export default defineConfig({
31
32
  plugins: [
32
33
  vue(),
33
34
  AutoImport({
34
- resolvers: [VantResolver()],
35
+ resolvers: [
36
+ VantResolver({
37
+ importStyle: 'css'
38
+ })
39
+ ],
40
+ dts: 'auto-imports.d.ts',
35
41
  }),
36
42
  Components({
37
- resolvers: [VantResolver()],
43
+ resolvers: [
44
+ VantResolver({
45
+ importStyle: 'css'
46
+ })
47
+ ],
48
+ dts: 'components.d.ts',
38
49
  })
39
50
  ],
40
51