@gx-design-vue/create-gx-cli 0.1.2 → 0.1.4

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.
Files changed (59) hide show
  1. package/README.md +4 -11
  2. package/package.json +3 -2
  3. package/src/main.js +9 -3
  4. package/template-mobile-vant-cli/.env +0 -0
  5. package/template-mobile-vant-cli/.env.pro +1 -1
  6. package/template-mobile-vant-cli/.env.production +2 -2
  7. package/template-mobile-vant-cli/.eslintignore +0 -1
  8. package/template-mobile-vant-cli/build/plugin/autoImport.ts +8 -10
  9. package/template-mobile-vant-cli/build/plugin/index.ts +2 -10
  10. package/template-mobile-vant-cli/build/plugin/mock.ts +5 -11
  11. package/template-mobile-vant-cli/build/plugin/viteMock/client.ts +88 -0
  12. package/template-mobile-vant-cli/build/plugin/viteMock/createMockServer.ts +271 -0
  13. package/template-mobile-vant-cli/build/plugin/viteMock/index.ts +69 -0
  14. package/template-mobile-vant-cli/build/plugin/viteMock/types.ts +48 -0
  15. package/template-mobile-vant-cli/build/plugin/viteMock/utils.ts +48 -0
  16. package/template-mobile-vant-cli/eslint.config.js +49 -0
  17. package/template-mobile-vant-cli/mock/_createProductionServer.ts +4 -4
  18. package/template-mobile-vant-cli/mock/datasSource/api/index.ts +0 -0
  19. package/template-mobile-vant-cli/package.json +26 -33
  20. package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +1 -2
  21. package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +7 -6
  22. package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +1 -1
  23. package/template-mobile-vant-cli/src/core/vant-design/index.ts +1 -1
  24. package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +8 -5
  25. package/template-mobile-vant-cli/src/layout/BasicLayout.vue +3 -3
  26. package/template-mobile-vant-cli/src/pages/home.vue +27 -27
  27. package/template-mobile-vant-cli/src/router/index.ts +3 -2
  28. package/template-mobile-vant-cli/src/router/typings.ts +1 -1
  29. package/template-mobile-vant-cli/src/settings/index.ts +2 -2
  30. package/template-mobile-vant-cli/src/store/modules/global.ts +1 -1
  31. package/template-mobile-vant-cli/src/utils/crypto/base64.ts +101 -0
  32. package/template-mobile-vant-cli/src/utils/{cryptoJS.ts → crypto/index.ts} +23 -5
  33. package/template-mobile-vant-cli/src/utils/env.ts +15 -17
  34. package/template-mobile-vant-cli/src/utils/pageTitle.ts +5 -3
  35. package/template-mobile-vant-cli/src/utils/request/XHR.ts +38 -30
  36. package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +32 -23
  37. package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +1 -3
  38. package/template-mobile-vant-cli/src/utils/request/index.ts +3 -4
  39. package/template-mobile-vant-cli/src/utils/request/typings.ts +74 -17
  40. package/template-mobile-vant-cli/src/utils/storage.ts +25 -18
  41. package/template-mobile-vant-cli/src/utils/util.ts +0 -5
  42. package/template-mobile-vant-cli/src/utils/validate.ts +191 -3
  43. package/template-mobile-vant-cli/tsconfig.json +8 -9
  44. package/template-mobile-vant-cli/types/{gx-components.d.ts → ant-design-import.d.ts} +3 -3
  45. package/template-mobile-vant-cli/types/auto-imports.d.ts +3 -0
  46. package/template-mobile-vant-cli/types/components.d.ts +2 -5
  47. package/template-mobile-vant-cli/types/global.d.ts +7 -4
  48. package/template-mobile-vant-cli/types/module.d.ts +15 -2
  49. package/template-mobile-vant-cli/types/plugins-auto-import.d.ts +14 -0
  50. package/template-mobile-vant-cli/types/response.d.ts +8 -5
  51. package/template-mobile-vant-cli/types/vant-import.d.ts +13 -0
  52. package/template-mobile-vant-cli/unocss.config.ts +101 -0
  53. package/template-mobile-vant-cli/vite.config.ts +43 -11
  54. package/template-mobile-vant-cli/.eslintrc.js +0 -64
  55. package/template-mobile-vant-cli/.stylelintignore +0 -3
  56. package/template-mobile-vant-cli/mock/api/index.ts +0 -66
  57. package/template-mobile-vant-cli/stylelint.config.js +0 -106
  58. /package/template-mobile-vant-cli/{postcss.config.js → postcss.config.cjs} +0 -0
  59. /package/template-mobile-vant-cli/{prettier.config.js → prettier.config.cjs} +0 -0
@@ -0,0 +1,48 @@
1
+ import fs from 'node:fs'
2
+
3
+ const toString = Object.prototype.toString
4
+
5
+ export function is(val: unknown, type: string) {
6
+ return toString.call(val) === `[object ${type}]`
7
+ }
8
+
9
+ export function fileExists(f: string) {
10
+ try {
11
+ fs.accessSync(f, fs.constants.W_OK);
12
+ return true;
13
+ } catch (error) {
14
+ return false;
15
+ }
16
+ }
17
+
18
+ export function isFunction<T = Function>(val: unknown): val is T {
19
+ return is(val, 'Function') || is(val, 'AsyncFunction')
20
+ }
21
+
22
+ export function isArray(val: any): val is Array<any> {
23
+ return val && Array.isArray(val)
24
+ }
25
+
26
+ export function isRegExp(val: unknown): val is RegExp {
27
+ return is(val, 'RegExp')
28
+ }
29
+
30
+ export function isAbsPath(path: string | undefined) {
31
+ if (!path) {
32
+ return false
33
+ }
34
+ // Windows 路径格式:C:\ 或 \\ 开头,或已含盘符(D:\path\to\file)
35
+ if (/^([a-zA-Z]:\\|\\\\|(?:\/|\uFF0F){2,})/.test(path)) {
36
+ return true
37
+ }
38
+ // Unix/Linux 路径格式:/ 开头
39
+ return /^\/[^/]/.test(path)
40
+ }
41
+
42
+ export function sleep(time: number) {
43
+ return new Promise((resolve) => {
44
+ setTimeout(() => {
45
+ resolve('')
46
+ }, time)
47
+ })
48
+ }
@@ -0,0 +1,49 @@
1
+ import antFuEslint from '@antfu/eslint-config'
2
+
3
+ export default antFuEslint({
4
+ vue: true,
5
+ vueJsx: false,
6
+ typescript: true,
7
+ gitignore: true,
8
+ markdown: true,
9
+ ignores: [
10
+ 'src/assets/**/*.js',
11
+ 'build/plugin/viteMock',
12
+ 'public',
13
+ 'tsconfig.*.json',
14
+ 'tsconfig.json'
15
+ ]
16
+ }, {
17
+ rules: {
18
+ 'curly': 0,
19
+ 'no-console': 0,
20
+ 'import/order': 0,
21
+ 'style/quote-props': 0,
22
+ 'style/brace-style': 0,
23
+ 'style/comma-dangle': 0,
24
+ 'style/multiline-ternary': 0,
25
+ 'prefer-regex-literals': 0,
26
+ 'antfu/top-level-function': 0,
27
+ 'vue/array-bracket-spacing': 0,
28
+ 'style/array-bracket-spacing': 0,
29
+ 'node/prefer-global/process': 0,
30
+ 'style/indent': 0,
31
+ 'prefer-template': 0,
32
+ 'dot-notation': 0,
33
+ 'no-cond-assign': 0,
34
+ 'no-useless-computed-key': 0,
35
+ 'node/no-deprecated-api': 0,
36
+ 'antfu/consistent-list-newline': 0,
37
+ 'import/no-mutable-exports': 0,
38
+ 'style/member-delimiter-style': 0,
39
+ 'unused-imports/no-unused-imports': 0,
40
+ 'eslint-comments/no-unlimited-disable': 0,
41
+ 'no-async-promise-executor': 0,
42
+ 'unicorn/escape-case': 0,
43
+ 'ts/method-signature-style': 0,
44
+ 'style/no-trailing-spaces': 0,
45
+ 'ts/consistent-type-imports': 0,
46
+ 'style/type-generic-spacing': 0,
47
+ 'prefer-promise-reject-errors': 0
48
+ }
49
+ })
@@ -1,14 +1,14 @@
1
- import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer'
1
+ import { createProdMockServer } from '../build/plugin/viteMock/client'
2
2
 
3
- const modules = import.meta.globEager('./api/*.ts')
3
+ const modules = import.meta.glob('./datasSource/**/*.ts', { eager: true })
4
4
 
5
5
  const mockModules: any[] = []
6
6
  Object.keys(modules).forEach((key) => {
7
7
  if (key.includes('/_')) {
8
8
  return
9
9
  }
10
- if (modules[key] && modules[key]['default']) mockModules.push(...modules[key]['default'])
11
- return
10
+ if (modules[key] && modules[key]['default'])
11
+ mockModules.push(...modules[key]['default'])
12
12
  })
13
13
 
14
14
  /**
@@ -1,42 +1,44 @@
1
1
  {
2
2
  "name": "gx-mobile-cli",
3
3
  "version": "0.0.0",
4
+ "type": "module",
4
5
  "scripts": {
5
6
  "dev": "vite",
6
- "build": "vue-tsc && vite build",
7
- "build:pro": "vue-tsc && vite build --mode pro",
7
+ "start:pro": "cross-env VITE_APP_ENV=pro vite",
8
+ "build": "vite build",
9
+ "build:pro": "vite build --mode pro",
8
10
  "preview": "vite preview"
9
11
  },
10
12
  "dependencies": {
11
- "@gx-design-vue/pro-hooks": "^0.1.1",
12
- "@gx-design-vue/pro-utils": "^0.1.1",
13
- "@vueuse/core": "^9.10.0",
14
- "@vueuse/shared": "^9.10.0",
15
- "axios": "^1.1.3",
13
+ "@gx-design-vue/pro-hooks": "^0.2.0-beta.19",
14
+ "@gx-design-vue/pro-utils": "^0.2.0-beta.26",
15
+ "@vueuse/core": "^10.7.2",
16
+ "@vueuse/shared": "^10.7.2",
17
+ "axios": "^1.6.7",
16
18
  "crypto-js": "^4.1.1",
17
19
  "dayjs": "^1.11.6",
18
20
  "lodash-es": "^4.17.21",
19
- "lodash-unified": "^1.0.3",
20
- "mockjs": "^1.1.0",
21
- "pinia": "^2.0.23",
21
+ "pinia": "2.1.7",
22
22
  "qs": "^6.11.0",
23
- "unocss": "^0.48.2",
24
- "vant": "^4.0.8",
25
- "vue": "^3.2.45",
23
+ "vant": "^4.8.8",
24
+ "vue": "^3.3.7",
26
25
  "vue-router": "^4.1.6"
27
26
  },
28
27
  "devDependencies": {
28
+ "@antfu/eslint-config": "^2.9.0",
29
29
  "@types/lodash-es": "^4.17.4",
30
- "@types/node": "^17.0.42",
30
+ "@types/node": "^20.11.19",
31
31
  "@typescript-eslint/eslint-plugin": "^5.20.0",
32
32
  "@typescript-eslint/parser": "^5.20.0",
33
- "@vitejs/plugin-vue": "^4.0.0",
34
- "@vitejs/plugin-vue-jsx": "^3.0.0",
33
+ "@vitejs/plugin-vue": "^5.0.4",
34
+ "@vitejs/plugin-vue-jsx": "^3.1.0",
35
35
  "autoprefixer": "^10.4.13",
36
- "eslint": "^8.13.0",
37
- "eslint-config-prettier": "^8.5.0",
38
- "eslint-plugin-prettier": "^4.0.0",
39
- "eslint-plugin-vue": "^8.6.0",
36
+ "unocss": "^0.58.5",
37
+ "mockjs": "^1.1.0",
38
+ "cross-env": "^7.0.3",
39
+ "connect": "^3.7.0",
40
+ "path-to-regexp": "^6.2.1",
41
+ "bundle-require": "^4.0.1",
40
42
  "less": "^4.1.3",
41
43
  "less-loader": "^11.1.0",
42
44
  "postcss": "^8.4.18",
@@ -44,21 +46,12 @@
44
46
  "postcss-less": "^6.0.0",
45
47
  "postcss-pxtorem": "^6.0.0",
46
48
  "prettier": "^2.7.1",
47
- "rollup": "^2.79.1",
48
- "stylelint": "^14.7.1",
49
- "stylelint-config-prettier": "^9.0.3",
50
- "stylelint-config-recommended": "^7.0.0",
51
- "stylelint-config-recommended-vue": "^1.4.0",
52
- "stylelint-config-standard": "^25.0.0",
53
- "stylelint-order": "^5.0.0",
54
- "typescript": "^4.6.4",
49
+ "typescript": "^5.3.3",
55
50
  "unplugin-auto-import": "^0.11.4",
56
51
  "unplugin-vue-components": "^0.22.9",
57
- "vite": "^4.0.4",
52
+ "vite": "^5.1.4",
58
53
  "vite-plugin-html": "^3.2.0",
59
- "vite-plugin-mock": "^2.9.6",
60
54
  "vite-plugin-vue-setup-extend": "^0.4.0",
61
- "vue-eslint-parser": "^9.1.0",
62
- "vue-tsc": "^1.0.9"
55
+ "vue-tsc": "^1.8.27"
63
56
  }
64
- }
57
+ }
@@ -5,10 +5,9 @@ import styles from './style.module.less'
5
5
  import 'vant/es/skeleton/style'
6
6
 
7
7
  const Proskeleton: FunctionalComponent<{ line: number; loading: boolean }> = (props, { slots }) => {
8
-
9
8
  const renderMapItem = () => {
10
9
  const show = []
11
- for(let i = 0; i < props.line; i += 1) {
10
+ for (let i = 0; i < props.line; i += 1) {
12
11
  show.push(
13
12
  <div class={styles.skeletonItem}>
14
13
  <Skeleton row={3} loading />
@@ -14,21 +14,21 @@ const PageContainer = defineComponent({
14
14
  name: 'GProPageContainer',
15
15
  inheritAttrs: false,
16
16
  props: {
17
- loading: Boolean as PropType<boolean>,
17
+ loading: Boolean as VuePropType<boolean>,
18
18
  hiddenSlot: {
19
- type: Boolean as PropType<boolean>,
19
+ type: Boolean as VuePropType<boolean>,
20
20
  default: true
21
21
  },
22
22
  loadingMsg: {
23
- type: String as PropType<string>,
23
+ type: String as VuePropType<string>,
24
24
  default: '加载中'
25
25
  },
26
26
  loadingType: {
27
- type: String as PropType<PageLoadingTpe>,
27
+ type: String as VuePropType<PageLoadingTpe>,
28
28
  default: 'toast'
29
29
  },
30
30
  bgcolor: {
31
- type: String as PropType<string>,
31
+ type: String as VuePropType<string>,
32
32
  default: '#fafafa'
33
33
  }
34
34
  },
@@ -47,7 +47,8 @@ const PageContainer = defineComponent({
47
47
  })
48
48
 
49
49
  watch(() => loading.value, (val) => {
50
- if (initStatus.value && val) initStatus.value = false
50
+ if (initStatus.value && val)
51
+ initStatus.value = false
51
52
  emit('update:loading', val)
52
53
  }, {
53
54
  deep: true,
@@ -2,7 +2,7 @@
2
2
  width: 100%;
3
3
  min-height: 100vh;
4
4
  padding: 15px;
5
- background: var(--van-doc-background-3);
5
+ background: var(--van-background-3);
6
6
 
7
7
  .pageContainerWrapper {
8
8
  position: relative;
@@ -1,4 +1,4 @@
1
- const vantDesign = (app) => {
1
+ const vantDesign = (_app) => {
2
2
  }
3
3
 
4
4
  export default vantDesign
@@ -3,7 +3,11 @@ import { ref, watch } from 'vue'
3
3
  import { closeToast, showLoadingToast } from 'vant'
4
4
  import type { PageLoadingTpe } from '@/components/PageContainer'
5
5
 
6
- export type SetLoadingParams<T> = { value: T; type?: PageLoadingTpe; message?: string }
6
+ export interface SetLoadingParams<T> {
7
+ value: T;
8
+ type?: PageLoadingTpe;
9
+ message?: string
10
+ }
7
11
 
8
12
  type ChangeLoadingFn<T> = ({ value, type, message }: SetLoadingParams<T>) => void
9
13
 
@@ -16,9 +20,7 @@ export default function usePageLoading<T, R = Ref<T>>({
16
20
  defaultMessage?: string;
17
21
  defaultLoading?: T | (() => T);
18
22
  }): [ R, ChangeLoadingFn<T> ] {
19
-
20
- const initValue: T =
21
- typeof defaultLoading === 'function' ? (defaultLoading as any)() : defaultLoading
23
+ const initValue: T = typeof defaultLoading === 'function' ? (defaultLoading as any)() : defaultLoading
22
24
 
23
25
  const pageLoading = ref(initValue) as Ref<T>
24
26
 
@@ -48,7 +50,8 @@ export default function usePageLoading<T, R = Ref<T>>({
48
50
  const changeLoading = ({ value, type, message }: SetLoadingParams<T>) => {
49
51
  pageLoading.value = value
50
52
  loadingMessage.value = message
51
- if (type) loadingType.value = type
53
+ if (type)
54
+ loadingType.value = type
52
55
  }
53
56
 
54
57
  return [ pageLoading as unknown as R, changeLoading ]
@@ -1,3 +1,6 @@
1
+ <script setup lang="ts">
2
+ </script>
3
+
1
4
  <template>
2
5
  <div :class="$style['basic-layout']">
3
6
  <RouterView>
@@ -8,9 +11,6 @@
8
11
  </div>
9
12
  </template>
10
13
 
11
- <script setup lang="ts">
12
- </script>
13
-
14
14
  <style lang="less" module>
15
15
  @import './basicLayout';
16
16
  </style>
@@ -1,22 +1,3 @@
1
- <template>
2
- <g-pro-page-container
3
- ref="pageContainer"
4
- v-model:loading="loading"
5
- :loadingMsg="loadingMsg"
6
- :hiddenSlot="hiddenSlot"
7
- >
8
- <div style="display: flex;flex-direction: column;gap: 20px;">
9
- <p>以下刷新只针对toast</p>
10
- <van-button @click="init(true)">刷新(隐藏子组件)</van-button>
11
- <van-button @click="init(false)">刷新(不隐藏子组件)</van-button>
12
- <van-button @click="changeLoading('切换中')">切换loading提示语</van-button>
13
- <van-button @click="toggleLoading(true)">刷新-调用方法-隐藏</van-button>
14
- <van-button @click="toggleLoading(false)">刷新-调用方法-不隐藏</van-button>
15
- <van-button @click="toggleLoading(false, '切换中')">刷新-调用方法-不隐藏-切换提示语</van-button>
16
- </div>
17
- </g-pro-page-container>
18
- </template>
19
-
20
1
  <script setup lang="ts">
21
2
  import { isBoolean } from '@gx-design-vue/pro-utils'
22
3
 
@@ -25,21 +6,22 @@ const pageContainer = ref()
25
6
  const loadingMsg = ref('加载中')
26
7
  const hiddenSlot = ref(true)
27
8
 
28
- onMounted(() => {
29
- init()
30
- })
31
-
32
9
  const init = (val?: boolean) => {
33
10
  loadingMsg.value = '加载中'
34
11
  loading.value = true
35
-
36
- if (isBoolean(val)) hiddenSlot.value = val
37
-
12
+
13
+ if (isBoolean(val))
14
+ hiddenSlot.value = val
15
+
38
16
  setTimeout(() => {
39
17
  loading.value = false
40
18
  }, 1000)
41
19
  }
42
20
 
21
+ onMounted(() => {
22
+ init()
23
+ })
24
+
43
25
  const changeLoading = (message: string) => {
44
26
  loadingMsg.value = message
45
27
  loading.value = true
@@ -64,8 +46,26 @@ const toggleLoading = (hiddenSlot: boolean, message?: string) => {
64
46
  })
65
47
  }, 1000)
66
48
  }
67
-
68
49
  </script>
69
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
70
  <style lang="less" scoped>
71
71
  </style>
@@ -1,5 +1,6 @@
1
1
  import type { App } from 'vue'
2
- import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
2
+ import type { RouteRecordRaw } from 'vue-router'
3
+ import { createRouter, createWebHashHistory } from 'vue-router'
3
4
  import settings from '@/settings'
4
5
  import getPageTitle from '@/utils/pageTitle'
5
6
  import { constantRoutes } from './routes'
@@ -18,7 +19,7 @@ const doRouterPermission = () => {
18
19
 
19
20
  // 配置路由器
20
21
  export function setupRouter(app: App<Element>) {
21
- app.use(router);
22
+ app.use(router)
22
23
 
23
24
  doRouterPermission()
24
25
  }
@@ -5,4 +5,4 @@ interface AppRouteRecordRaw {
5
5
  homePage?: number;
6
6
  }
7
7
 
8
- export type AppRouteModule = AppRouteRecordRaw & RouteRecordRaw;
8
+ export type AppRouteModule = AppRouteRecordRaw & RouteRecordRaw
@@ -3,8 +3,8 @@ export default {
3
3
  tokenName: 'token',
4
4
  contentType: 'application/json;charset=UTF-8',
5
5
  requestPrefix: '',
6
- //最长请求时间
6
+ // 最长请求时间
7
7
  requestTimeout: 10000,
8
- //操作正常code,支持String、Array、int多种类型
8
+ // 操作正常code,支持String、Array、int多种类型
9
9
  successCode: [ 200, 0 ]
10
10
  }
@@ -1,6 +1,6 @@
1
1
  import { reactive, toRefs } from 'vue'
2
2
  import { defineStore } from 'pinia'
3
- import { deepCopy } from '@/utils/util'
3
+ import { deepCopy } from '@gx-design-vue/pro-utils'
4
4
 
5
5
  /**
6
6
  * @Author gx12358
@@ -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
+ }
@@ -2,12 +2,28 @@ import 'crypto-js/enc-utf8'
2
2
  import 'crypto-js/tripledes'
3
3
  import 'crypto-js/sha1'
4
4
  import * as CryptoJS from 'crypto-js/core'
5
+ import CryptoProJS from 'crypto-js'
5
6
  import { isJSONStr } from '@/utils/validate'
6
- import { isObject, isArray } from '@gx-design-vue/pro-utils'
7
+ import { isArray, isObject } from '@gx-design-vue/pro-utils'
7
8
 
8
- const key = '1234123412ABCDEF' //十六位十六进制数作为密钥
9
+ const key = '1234123412ABCDEF' // 十六位十六进制数作为密钥
9
10
 
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
+ // 加密方法
11
27
  export function Encrypt(word) {
12
28
  let str: string | object = word
13
29
  if (isObject(word) || isArray(word)) {
@@ -23,7 +39,7 @@ export function Encrypt(word) {
23
39
  return CryptoJS.enc.Base64.stringify(encrypted.ciphertext)
24
40
  }
25
41
 
26
- //解密方法
42
+ // 解密方法
27
43
  export function Decrypt(word) {
28
44
  const keyHex = CryptoJS.enc.Utf8.parse(key)
29
45
  const ivHex = CryptoJS.enc.Utf8.parse(key)
@@ -35,5 +51,7 @@ export function Decrypt(word) {
35
51
  padding: CryptoJS.pad.Pkcs7
36
52
  })
37
53
  const decryptedStr = decrypted.toString(CryptoJS.enc.Utf8)
38
- return isJSONStr(decryptedStr.toString()) ? JSON.parse(decryptedStr.toString()) : decryptedStr.toString()
54
+ return isJSONStr(decryptedStr.toString())
55
+ ? JSON.parse(decryptedStr.toString())
56
+ : decryptedStr.toString()
39
57
  }
@@ -2,49 +2,47 @@
2
2
  * @Author gx12358
3
3
  * @DateTime 2022/4/1
4
4
  * @lastTime 2022/4/1
5
- * @description 环境:开发
5
+ * @description 环境:本地开发环境
6
6
  */
7
7
  export function isDev(): boolean {
8
- const DEV = typeViteEnv('VITE_USE_MODE') === 'development'
9
- return DEV
8
+ return typeViteEnv('VITE_APP_ENV') === 'dev'
10
9
  }
11
10
 
12
11
  /**
13
12
  * @Author gx12358
14
13
  * @DateTime 2022/4/1
15
14
  * @lastTime 2022/4/1
16
- * @description 环境:测试
15
+ * @description 环境:正式
17
16
  */
18
- export function isTest(): boolean {
19
- const PRO = typeViteEnv('VITE_USE_MODE') === 'test'
20
- return PRO
17
+ export function isPro(): boolean {
18
+ return typeViteEnv('VITE_USE_MODE') === 'pro'
21
19
  }
22
20
 
23
21
  /**
24
22
  * @Author gx12358
25
23
  * @DateTime 2022/4/1
26
24
  * @lastTime 2022/4/1
27
- * @description 环境:正式
25
+ * @description 环境:非本地开发环境
28
26
  */
29
- export function isPro(): boolean {
30
- return typeViteEnv('VITE_USE_MODE') === 'production'
27
+ export function isBuild(): boolean {
28
+ return typeViteEnv('VITE_NODE_ENV') === 'production'
31
29
  }
32
30
 
33
31
  /**
34
32
  * @Author gx12358
35
33
  * @DateTime 2022/4/1
36
34
  * @lastTime 2022/4/1
37
- * @description 环境:测试、正式
35
+ * @description 当前联调环境
38
36
  */
39
- export function isBuild(): boolean {
40
- return typeViteEnv('VITE_USE_MODE') !== 'development'
37
+ export function currentMode() {
38
+ return typeViteEnv('VITE_USE_MODE')
41
39
  }
42
40
 
43
- export function typeViteEnv(key: ViteEnvKey) {
44
- let value = import.meta.env[key]
45
- if (value) {
46
- value = (value as string).replace(/\\n/g, '\n')
41
+ export function typeViteEnv<T extends keyof ViteEnv>(key: T): ViteEnv[T] | undefined {
42
+ let value: any = (import.meta as any).env[key]
47
43
 
44
+ if (value && typeof value === 'string') {
45
+ value = value.replace(/\\n/g, '\n') as ViteEnv[T]
48
46
  value = value === 'true' ? true : value === 'false' ? false : value
49
47
  }
50
48