@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.
Files changed (102) hide show
  1. package/README.md +4 -11
  2. package/package.json +3 -2
  3. package/template-mobile-vant-cli/.editorconfig +19 -0
  4. package/template-mobile-vant-cli/.env +0 -0
  5. package/template-mobile-vant-cli/.env.development +19 -0
  6. package/template-mobile-vant-cli/.env.pro +19 -0
  7. package/template-mobile-vant-cli/.env.production +19 -0
  8. package/template-mobile-vant-cli/.eslintignore +15 -0
  9. package/template-mobile-vant-cli/.prettierignore +9 -0
  10. package/template-mobile-vant-cli/build/cdn.ts +5 -0
  11. package/template-mobile-vant-cli/build/generateModifyVars.ts +7 -0
  12. package/template-mobile-vant-cli/build/optimizer.ts +18 -0
  13. package/template-mobile-vant-cli/build/plugin/autoImport.ts +24 -0
  14. package/template-mobile-vant-cli/build/plugin/html.ts +26 -0
  15. package/template-mobile-vant-cli/build/plugin/index.ts +42 -0
  16. package/template-mobile-vant-cli/build/plugin/mock.ts +14 -0
  17. package/template-mobile-vant-cli/build/plugin/viteMock/client.ts +88 -0
  18. package/template-mobile-vant-cli/build/plugin/viteMock/createMockServer.ts +271 -0
  19. package/template-mobile-vant-cli/build/plugin/viteMock/index.ts +69 -0
  20. package/template-mobile-vant-cli/build/plugin/viteMock/types.ts +48 -0
  21. package/template-mobile-vant-cli/build/plugin/viteMock/utils.ts +48 -0
  22. package/template-mobile-vant-cli/build/script/postBuild.ts +14 -0
  23. package/template-mobile-vant-cli/eslint.config.js +49 -0
  24. package/template-mobile-vant-cli/index.html +24 -0
  25. package/template-mobile-vant-cli/mock/_createProductionServer.ts +19 -0
  26. package/template-mobile-vant-cli/mock/datasSource/api/index.ts +0 -0
  27. package/template-mobile-vant-cli/mock/utils.ts +9 -0
  28. package/template-mobile-vant-cli/package.json +57 -0
  29. package/template-mobile-vant-cli/postcss.config.cjs +8 -0
  30. package/template-mobile-vant-cli/prettier.config.cjs +18 -0
  31. package/template-mobile-vant-cli/public/favicon.ico +0 -0
  32. package/template-mobile-vant-cli/public/js/flexible.js +44 -0
  33. package/template-mobile-vant-cli/src/App.vue +5 -0
  34. package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +29 -0
  35. package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +115 -0
  36. package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +14 -0
  37. package/template-mobile-vant-cli/src/core/gx-design/index.ts +7 -0
  38. package/template-mobile-vant-cli/src/core/index.ts +12 -0
  39. package/template-mobile-vant-cli/src/core/vant-design/index.ts +4 -0
  40. package/template-mobile-vant-cli/src/design/config.less +0 -0
  41. package/template-mobile-vant-cli/src/design/index.less +3 -0
  42. package/template-mobile-vant-cli/src/design/reset.less +155 -0
  43. package/template-mobile-vant-cli/src/design/root.less +3 -0
  44. package/template-mobile-vant-cli/src/design/vant.less +2 -0
  45. package/template-mobile-vant-cli/src/global.less +1 -0
  46. package/template-mobile-vant-cli/src/hooks/web/index.ts +5 -0
  47. package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +58 -0
  48. package/template-mobile-vant-cli/src/layout/BasicLayout.vue +16 -0
  49. package/template-mobile-vant-cli/src/layout/basicLayout.less +11 -0
  50. package/template-mobile-vant-cli/src/main.ts +27 -0
  51. package/template-mobile-vant-cli/src/pages/home.vue +71 -0
  52. package/template-mobile-vant-cli/src/router/index.ts +25 -0
  53. package/template-mobile-vant-cli/src/router/routes.ts +20 -0
  54. package/template-mobile-vant-cli/src/router/typings.ts +8 -0
  55. package/template-mobile-vant-cli/src/services/index.ts +31 -0
  56. package/template-mobile-vant-cli/src/settings/index.ts +10 -0
  57. package/template-mobile-vant-cli/src/store/index.ts +17 -0
  58. package/template-mobile-vant-cli/src/store/modules/global.ts +30 -0
  59. package/template-mobile-vant-cli/src/utils/crypto/base64.ts +101 -0
  60. package/template-mobile-vant-cli/src/utils/crypto/index.ts +57 -0
  61. package/template-mobile-vant-cli/src/utils/env.ts +50 -0
  62. package/template-mobile-vant-cli/src/utils/pageTitle.ts +14 -0
  63. package/template-mobile-vant-cli/src/utils/request/XHR.ts +139 -0
  64. package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +69 -0
  65. package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +9 -0
  66. package/template-mobile-vant-cli/src/utils/request/index.ts +142 -0
  67. package/template-mobile-vant-cli/src/utils/request/typings.ts +171 -0
  68. package/template-mobile-vant-cli/src/utils/storage.ts +198 -0
  69. package/template-mobile-vant-cli/src/utils/util.ts +27 -0
  70. package/template-mobile-vant-cli/src/utils/validate.ts +216 -0
  71. package/template-mobile-vant-cli/tsconfig.json +42 -0
  72. package/template-mobile-vant-cli/types/ant-design-import.d.ts +13 -0
  73. package/template-mobile-vant-cli/types/auto-imports.d.ts +64 -0
  74. package/template-mobile-vant-cli/types/components.d.ts +12 -0
  75. package/template-mobile-vant-cli/types/global.d.ts +39 -0
  76. package/template-mobile-vant-cli/types/module.d.ts +20 -0
  77. package/template-mobile-vant-cli/types/plugins-auto-import.d.ts +14 -0
  78. package/template-mobile-vant-cli/types/response.d.ts +15 -0
  79. package/template-mobile-vant-cli/types/vant-import.d.ts +13 -0
  80. package/template-mobile-vant-cli/unocss.config.ts +101 -0
  81. package/template-mobile-vant-cli/vite.config.ts +145 -0
  82. package/template-mobile-vant-html/css/global.css +293 -0
  83. package/template-mobile-vant-html/css/global.css.map +1 -0
  84. package/template-mobile-vant-html/css/global.less +293 -0
  85. package/template-mobile-vant-html/css/index.css +20 -0
  86. package/template-mobile-vant-html/css/index.css.map +1 -0
  87. package/template-mobile-vant-html/css/index.less +21 -0
  88. package/template-mobile-vant-html/image/disconnected.svg +60 -0
  89. package/template-mobile-vant-html/image/empty.svg +52 -0
  90. package/template-mobile-vant-html/image/error.svg +53 -0
  91. package/template-mobile-vant-html/image/loading.svg +1 -0
  92. package/template-mobile-vant-html/index.html +91 -0
  93. package/template-mobile-vant-html/js/index.js +29 -0
  94. package/template-mobile-vant-html/js/plugin/day.min.js +1 -0
  95. package/template-mobile-vant-html/js/plugin/fastclick.js +730 -0
  96. package/template-mobile-vant-html/js/plugin/jquery.min.js +2 -0
  97. package/template-mobile-vant-html/js/plugin/rem.js +28 -0
  98. package/template-mobile-vant-html/js/utils/appUtil.js +70 -0
  99. package/template-mobile-vant-html/js/utils/config.js +3 -0
  100. package/template-mobile-vant-html/js/utils/request.js +61 -0
  101. package/template-mobile-vant-html/js/utils/utils.js +65 -0
  102. package/template-mobile-vant-html/js/utils/validate.js +292 -0
@@ -0,0 +1,69 @@
1
+ (async () => {
2
+ try {
3
+ await import('mockjs')
4
+ } catch (e) {
5
+ throw new Error('vite-plugin-vue-mock requires mockjs to be present in the dependency tree.')
6
+ }
7
+ })()
8
+
9
+ import type { Plugin, ResolvedConfig } from 'vite'
10
+ import { normalizePath } from 'vite'
11
+ import path from 'node:path'
12
+ import type { ViteMockOptions } from './types'
13
+ import { fileExists } from './utils'
14
+ import { createMockServer, requestMiddleware } from './createMockServer'
15
+
16
+ function getDefaultPath(supportTs = true) {
17
+ return path.resolve(process.cwd(), `src/main.${supportTs ? 'ts' : 'js'}`)
18
+ }
19
+
20
+ export function viteMockServe(opt: ViteMockOptions = {}): Plugin {
21
+ let isDev = false
22
+ let needSourcemap = false
23
+ let config: ResolvedConfig
24
+ let defaultPath = getDefaultPath()
25
+ if (!fileExists(defaultPath)) {
26
+ defaultPath = getDefaultPath(false)
27
+ if (!fileExists(defaultPath)) {
28
+ defaultPath = ''
29
+ }
30
+ }
31
+
32
+ const defaultEnter = normalizePath(defaultPath)
33
+
34
+ const { injectFile = defaultEnter } = opt
35
+
36
+ return {
37
+ name: 'vite:mock',
38
+ enforce: 'pre' as const,
39
+ configResolved(resolvedConfig) {
40
+ config = resolvedConfig
41
+ isDev = config.command === 'serve'
42
+ needSourcemap = !!resolvedConfig.build.sourcemap
43
+ isDev && createMockServer(opt, config)
44
+ },
45
+
46
+ configureServer: async ({ middlewares }) => {
47
+ const { enable = isDev } = opt
48
+ if (!enable) {
49
+ return
50
+ }
51
+ const middleware = await requestMiddleware(opt)
52
+ middlewares.use(middleware)
53
+ },
54
+ transform: (code, id) => {
55
+ if (isDev || !injectFile || !id.endsWith(injectFile)) {
56
+ return null
57
+ }
58
+
59
+ const { injectCode = '' } = opt
60
+
61
+ return {
62
+ map: needSourcemap ? this.getCombinedSourcemap() : null,
63
+ code: `${code}\n${injectCode}`
64
+ }
65
+ }
66
+ }
67
+ }
68
+
69
+ export * from './types'
@@ -0,0 +1,48 @@
1
+ import { IncomingMessage, ServerResponse } from 'http'
2
+
3
+ export interface ViteMockOptions {
4
+ mockPath?: string;
5
+ configPath?: string;
6
+ injectFile?: string;
7
+ injectCode?: string;
8
+ ignore?: RegExp | ((fileName: string) => boolean);
9
+ watchFiles?: boolean;
10
+ enable?: boolean;
11
+ cors?: boolean;
12
+ /**
13
+ * Automatic recognition, no need to configure again
14
+ * @deprecated Deprecated after 2.8.0
15
+ */
16
+ supportTs?: boolean;
17
+ logger?: boolean;
18
+ }
19
+
20
+ export interface RespThisType {
21
+ req: IncomingMessage
22
+ res: ServerResponse
23
+ parseJson: () => any
24
+ }
25
+
26
+ export type MethodType = 'get' | 'post' | 'put' | 'delete' | 'patch'
27
+
28
+ export type Recordable<T = any> = Record<string, T>
29
+
30
+ export declare interface MockMethod {
31
+ url: string
32
+ method?: MethodType
33
+ timeout?: number
34
+ statusCode?: number
35
+ response?:
36
+ | ((
37
+ this: RespThisType,
38
+ opt: { url: Recordable; body: Recordable; query: Recordable; headers: Recordable },
39
+ ) => any)
40
+ | any
41
+ rawResponse?: (this: RespThisType, req: IncomingMessage, res: ServerResponse) => void
42
+ }
43
+
44
+ export interface MockConfig {
45
+ env: Record<string, any>
46
+ mode: string
47
+ command: 'build' | 'serve'
48
+ }
@@ -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,14 @@
1
+ // #!/usr/bin/env node
2
+ import chalk from 'chalk'
3
+
4
+ import pkg from '../../package.json'
5
+
6
+ export const runBuild = async () => {
7
+ try {
8
+ console.log(`✨ ${chalk.cyan(`[${pkg.name}]`)}` + ' - build successfully!')
9
+ } catch (error) {
10
+ console.log(chalk.red('vite build error:\n' + error))
11
+ process.exit(1)
12
+ }
13
+ }
14
+ runBuild()
@@ -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
+ })
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html lang="zh">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" href="/favicon.ico" type="image/x-icon" />
6
+ <meta
7
+ name="viewport"
8
+ content="width=device-width,viewport-fit=cover,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"
9
+ />
10
+ <title>vue-vant-mobile</title>
11
+ <% for (var i in injectLink) { %>
12
+ <link rel="stylesheet" type="text/css" href="<%= injectLink[i] %>" />
13
+ <% } %>
14
+ </head>
15
+ <body>
16
+ <div id="app"></div>
17
+ <% for (var i in injectScript) { %>
18
+ <script type="text/javascript" src="<%= injectScript[i] %>"></script>
19
+ <% } %>
20
+ <script type="module" src="/src/main.ts"></script>
21
+ <%- injectVlogScript %>
22
+ <script src="/js/flexible.js"></script>
23
+ </body>
24
+ </html>
@@ -0,0 +1,19 @@
1
+ import { createProdMockServer } from '../build/plugin/viteMock/client'
2
+
3
+ const modules = import.meta.glob('./datasSource/**/*.ts', { eager: true })
4
+
5
+ const mockModules: any[] = []
6
+ Object.keys(modules).forEach((key) => {
7
+ if (key.includes('/_')) {
8
+ return
9
+ }
10
+ if (modules[key] && modules[key]['default'])
11
+ mockModules.push(...modules[key]['default'])
12
+ })
13
+
14
+ /**
15
+ * Used in a production environment. Need to manually import all modules
16
+ */
17
+ export function setupProdMockServer() {
18
+ createProdMockServer(mockModules)
19
+ }
@@ -0,0 +1,9 @@
1
+ export const builder = (config?: Partial<ResponseResult>) => {
2
+ const code = config?.code || 200
3
+ const result: ResponseResult = {
4
+ ...config,
5
+ code,
6
+ msg: config?.msg || code ? 'success' : 'Request failed'
7
+ }
8
+ return result
9
+ }
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "gx-mobile-cli",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "scripts": {
6
+ "dev": "vite",
7
+ "start:pro": "cross-env VITE_APP_ENV=pro vite",
8
+ "build": "vite build",
9
+ "build:pro": "vite build --mode pro",
10
+ "preview": "vite preview"
11
+ },
12
+ "dependencies": {
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",
18
+ "crypto-js": "^4.1.1",
19
+ "dayjs": "^1.11.6",
20
+ "lodash-es": "^4.17.21",
21
+ "pinia": "2.1.7",
22
+ "qs": "^6.11.0",
23
+ "vant": "^4.8.8",
24
+ "vue": "^3.3.7",
25
+ "vue-router": "^4.1.6"
26
+ },
27
+ "devDependencies": {
28
+ "@antfu/eslint-config": "^2.9.0",
29
+ "@types/lodash-es": "^4.17.4",
30
+ "@types/node": "^20.11.19",
31
+ "@typescript-eslint/eslint-plugin": "^5.20.0",
32
+ "@typescript-eslint/parser": "^5.20.0",
33
+ "@vitejs/plugin-vue": "^5.0.4",
34
+ "@vitejs/plugin-vue-jsx": "^3.1.0",
35
+ "autoprefixer": "^10.4.13",
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",
42
+ "less": "^4.1.3",
43
+ "less-loader": "^11.1.0",
44
+ "postcss": "^8.4.18",
45
+ "postcss-html": "^1.5.0",
46
+ "postcss-less": "^6.0.0",
47
+ "postcss-pxtorem": "^6.0.0",
48
+ "prettier": "^2.7.1",
49
+ "typescript": "^5.3.3",
50
+ "unplugin-auto-import": "^0.11.4",
51
+ "unplugin-vue-components": "^0.22.9",
52
+ "vite": "^5.1.4",
53
+ "vite-plugin-html": "^3.2.0",
54
+ "vite-plugin-vue-setup-extend": "^0.4.0",
55
+ "vue-tsc": "^1.8.27"
56
+ }
57
+ }
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ plugins: {
3
+ 'postcss-pxtorem': {
4
+ rootValue: 37.5,
5
+ propList: ['*'],
6
+ },
7
+ },
8
+ };
@@ -0,0 +1,18 @@
1
+ module.exports = {
2
+ printWidth: 100,
3
+ useTabs: false,
4
+ semi: false,
5
+ singleQuote: true,
6
+ quoteProps: 'as-needed',
7
+ bracketSpacing: true,
8
+ trailingComma: 'none',
9
+ jsxBracketSameLine: false,
10
+ jsxSingleQuote: false,
11
+ arrowParens: 'always',
12
+ insertPragma: false,
13
+ requirePragma: false,
14
+ proseWrap: 'never',
15
+ htmlWhitespaceSensitivity: 'strict',
16
+ endOfLine: 'auto',
17
+ rangeStart: 0,
18
+ };
@@ -0,0 +1,44 @@
1
+ (function flexible (window, document) {
2
+ var docEl = document.documentElement
3
+ var dpr = window.devicePixelRatio || 1
4
+
5
+ // adjust body font size
6
+ function setBodyFontSize () {
7
+ if (document.body) {
8
+ document.body.style.fontSize = (12 * dpr) + 'px'
9
+ }
10
+ else {
11
+ document.addEventListener('DOMContentLoaded', setBodyFontSize)
12
+ }
13
+ }
14
+ setBodyFontSize();
15
+
16
+ // set 1rem = viewWidth / 10
17
+ function setRemUnit () {
18
+ var rem = (docEl.clientWidth < 600 ? docEl.clientWidth : 600) / 10
19
+ docEl.style.fontSize = rem + 'px'
20
+ }
21
+
22
+ setRemUnit()
23
+
24
+ // reset rem unit on page resize
25
+ window.addEventListener('resize', setRemUnit)
26
+ window.addEventListener('pageshow', function (e) {
27
+ if (e.persisted) {
28
+ setRemUnit()
29
+ }
30
+ })
31
+
32
+ // detect 0.5px supports
33
+ if (dpr >= 2) {
34
+ var fakeBody = document.createElement('body')
35
+ var testElement = document.createElement('div')
36
+ testElement.style.border = '.5px solid transparent'
37
+ fakeBody.appendChild(testElement)
38
+ docEl.appendChild(fakeBody)
39
+ if (testElement.offsetHeight === 1) {
40
+ docEl.classList.add('hairlines')
41
+ }
42
+ docEl.removeChild(fakeBody)
43
+ }
44
+ }(window, document))
@@ -0,0 +1,5 @@
1
+ <template>
2
+ <div id="gx-pro-mobile">
3
+ <router-view />
4
+ </div>
5
+ </template>
@@ -0,0 +1,29 @@
1
+ import type { FunctionalComponent } from 'vue'
2
+ import { Skeleton } from 'vant'
3
+ import styles from './style.module.less'
4
+
5
+ import 'vant/es/skeleton/style'
6
+
7
+ const Proskeleton: FunctionalComponent<{ line: number; loading: boolean }> = (props, { slots }) => {
8
+ const renderMapItem = () => {
9
+ const show = []
10
+ for (let i = 0; i < props.line; i += 1) {
11
+ show.push(
12
+ <div class={styles.skeletonItem}>
13
+ <Skeleton row={3} loading />
14
+ </div>
15
+ )
16
+ }
17
+ return show
18
+ }
19
+
20
+ return (
21
+ <>
22
+ {
23
+ props.loading ? renderMapItem() : <>{ slots.default?.() }</>
24
+ }
25
+ </>
26
+ )
27
+ }
28
+
29
+ export default Proskeleton
@@ -0,0 +1,115 @@
1
+ import { defineComponent, toRefs, watch } from 'vue'
2
+ import { usePageLoading } from '@gx-mobile/hooks/web'
3
+ import ProSkeleton from './ProSkeleton'
4
+ import styles from './style.module.less'
5
+ import type { SetLoadingParams } from '@gx-mobile/hooks/web/usePageLoading'
6
+
7
+ export type PageLoadingTpe = 'toast' | 'skeleton'
8
+
9
+ type ChangeLoadingParams<T> = Omit<SetLoadingParams<T>, 'type'> & {
10
+ hiddenSlot?: boolean;
11
+ }
12
+
13
+ const PageContainer = defineComponent({
14
+ name: 'GProPageContainer',
15
+ inheritAttrs: false,
16
+ props: {
17
+ loading: Boolean as VuePropType<boolean>,
18
+ hiddenSlot: {
19
+ type: Boolean as VuePropType<boolean>,
20
+ default: true
21
+ },
22
+ loadingMsg: {
23
+ type: String as VuePropType<string>,
24
+ default: '加载中'
25
+ },
26
+ loadingType: {
27
+ type: String as VuePropType<PageLoadingTpe>,
28
+ default: 'toast'
29
+ },
30
+ bgcolor: {
31
+ type: String as VuePropType<string>,
32
+ default: '#fafafa'
33
+ }
34
+ },
35
+ emits: [ 'update:loading' ],
36
+ setup(props, { slots, expose, emit }) {
37
+ const { loading: loadingRef, loadingType, loadingMsg, hiddenSlot } = toRefs(props)
38
+
39
+ const initStatus = ref(true)
40
+
41
+ const hiddenSlotRef = ref(props.hiddenSlot)
42
+
43
+ const [ loading, setLoading ] = usePageLoading({
44
+ defaultType: loadingType.value,
45
+ defaultMessage: loadingMsg.value,
46
+ defaultLoading: loadingRef.value
47
+ })
48
+
49
+ watch(() => loading.value, (val) => {
50
+ if (initStatus.value && val)
51
+ initStatus.value = false
52
+ emit('update:loading', val)
53
+ }, {
54
+ deep: true,
55
+ immediate: true
56
+ })
57
+
58
+ watch(() => loadingRef.value, (val) => {
59
+ if (loadingType.value === 'toast') {
60
+ setLoading({
61
+ value: val,
62
+ type: loadingType.value,
63
+ message: loadingMsg.value
64
+ })
65
+ } else if (initStatus.value || !val) {
66
+ setLoading({
67
+ value: val,
68
+ type: loadingType.value,
69
+ message: loadingMsg.value
70
+ })
71
+ }
72
+ })
73
+
74
+ watch(() => hiddenSlot.value, (val) => {
75
+ hiddenSlotRef.value = val
76
+ }, {
77
+ immediate: true
78
+ })
79
+
80
+ const changeLoading = ({
81
+ value,
82
+ message,
83
+ hiddenSlot
84
+ }: ChangeLoadingParams<boolean>) => {
85
+ if (loadingType.value === 'toast') {
86
+ hiddenSlotRef.value = hiddenSlot
87
+ setLoading({ value, message, type: loadingType.value })
88
+ }
89
+ }
90
+
91
+ expose({
92
+ toggleLoading: changeLoading
93
+ })
94
+
95
+ return () => {
96
+ return (
97
+ <div class={styles.pageContainer} style={{ backgroundColor: props.bgcolor }}>
98
+ <div class={styles.pageContainerWrapper}>
99
+ {
100
+ loadingType.value === 'skeleton'
101
+ ? (
102
+ <ProSkeleton line={3} loading={loading.value}>
103
+ {slots.default?.()}
104
+ </ProSkeleton>
105
+ )
106
+ : ((!loading.value || !hiddenSlotRef.value) && <>{slots.default?.()}</>)
107
+ }
108
+ </div>
109
+ </div>
110
+ )
111
+ }
112
+ }
113
+ })
114
+
115
+ export default PageContainer
@@ -0,0 +1,14 @@
1
+ .pageContainer {
2
+ width: 100%;
3
+ min-height: 100vh;
4
+ padding: 15px;
5
+ background: var(--van-background-3);
6
+
7
+ .pageContainerWrapper {
8
+ position: relative;
9
+ }
10
+
11
+ .skeletonItem + .skeletonItem {
12
+ margin-top: 50px;
13
+ }
14
+ }
@@ -0,0 +1,7 @@
1
+ import PageContainer from '@/components/PageContainer'
2
+
3
+ const vantDesign = (app) => {
4
+ app.component('g-pro-page-container', PageContainer)
5
+ }
6
+
7
+ export default vantDesign
@@ -0,0 +1,12 @@
1
+ import dayjs from 'dayjs'
2
+ import 'dayjs/locale/zh-cn'
3
+
4
+ dayjs.locale('zh-cn')
5
+
6
+ import vantDesign from './vant-design'
7
+ import gxDesign from './gx-design'
8
+
9
+ export function setupGlobCommon(app) {
10
+ gxDesign(app)
11
+ vantDesign(app)
12
+ }
@@ -0,0 +1,4 @@
1
+ const vantDesign = (_app) => {
2
+ }
3
+
4
+ export default vantDesign
@@ -0,0 +1,3 @@
1
+ @import './root';
2
+ @import './reset';
3
+ @import './vant';