Explorar o código

Merge branch 'master' into luohl

* master:
  ~
luohailiang hai 1 ano
pai
achega
1131309f3f
Modificáronse 4 ficheiros con 220 adicións e 129 borrados
  1. 0 4
      auto-imports.d.ts
  2. 93 0
      plugins/vite-plugin-conditional-compile.ts
  3. 120 120
      src/store/index.ts
  4. 7 5
      vite.config.ts

+ 0 - 4
auto-imports.d.ts

@@ -12,8 +12,6 @@ declare global {
   const $shallowRef: typeof import('vue/macros')['$shallowRef']
   const $toRef: typeof import('vue/macros')['$toRef']
   const EffectScope: typeof import('vue')['EffectScope']
-  const ElMessage: typeof import('element-plus/es')['ElMessage']
-  const ElMessageBox: typeof import('element-plus/es')['ElMessageBox']
   const asyncComputed: typeof import('@vueuse/core')['asyncComputed']
   const autoResetRef: typeof import('@vueuse/core')['autoResetRef']
   const computed: typeof import('vue')['computed']
@@ -300,8 +298,6 @@ declare module 'vue' {
     readonly $shallowRef: UnwrapRef<typeof import('vue/macros')['$shallowRef']>
     readonly $toRef: UnwrapRef<typeof import('vue/macros')['$toRef']>
     readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
-    readonly ElMessage: UnwrapRef<typeof import('element-plus/es')['ElMessage']>
-    readonly ElMessageBox: UnwrapRef<typeof import('element-plus/es')['ElMessageBox']>
     readonly asyncComputed: UnwrapRef<typeof import('@vueuse/core')['asyncComputed']>
     readonly autoResetRef: UnwrapRef<typeof import('@vueuse/core')['autoResetRef']>
     readonly computed: UnwrapRef<typeof import('vue')['computed']>

+ 93 - 0
plugins/vite-plugin-conditional-compile.ts

@@ -0,0 +1,93 @@
+import type { FilterPattern, Plugin, ResolvedConfig } from 'vite'
+
+import MagicString from 'magic-string'
+import { createFilter } from 'vite'
+
+interface Options {
+  /**
+   * @default ["**\/*"]
+   */
+  include: FilterPattern
+  /**
+   * @default []
+   */
+  exclude: FilterPattern
+}
+
+type UserOptions = Partial<Options>
+
+type ResolvedOptions = Options
+let config: ResolvedConfig = undefined!
+
+const replaceMatched = (code: string, id: string) => {
+  const env = config.env
+  const source = new MagicString(code, {
+    filename: id,
+  })
+
+  source.replace(
+    /^.*?#if(n?)def\s*(\S+).*[\r\n]{1,2}([\s\S]+?)\s*.*?#endif.*?$/gm,
+    /**
+     * 条件替换
+     * @param _ 匹配的字符串
+     * @param $1 是否为 not 模式
+     * @param $2 条件
+     * @param $3 code
+     */
+    (_, $1, $2, $3) => {
+      const isNot = !!$1
+      const isKeep = $2.split('||').some((v: string) => {
+        let flag = false
+        const [key, value] = v.split('=')
+        if (value === undefined)
+          flag = !!env[key]
+
+        else
+          flag = String(env[key]) === value
+
+        flag = isNot ? !flag : flag
+        return flag
+      })
+      return isKeep ? $3 : ''
+    },
+  )
+
+  if (source.hasChanged()) {
+    return {
+      code: source.toString(),
+      map: source.generateMap({
+        source: id,
+        file: `${id}.map`,
+        includeContent: true,
+      }),
+    }
+  }
+}
+
+const resolveOptions = (userOptions: UserOptions): ResolvedOptions => {
+  return {
+    include: ['**/*'],
+    exclude: [],
+    ...userOptions,
+  }
+}
+
+const VitePluginConditionalCompile = (
+  userOptions: UserOptions = {},
+): Plugin => {
+  const options = resolveOptions(userOptions)
+  return {
+    name: 'vite-plugin-conditional-compile',
+    enforce: 'pre',
+    configResolved(_config) {
+      config = _config
+    },
+    transform(code, id) {
+      const filter = createFilter(options.include, options.exclude)
+      if (filter(id))
+        return replaceMatched(code, id)
+    },
+  }
+}
+
+export default VitePluginConditionalCompile

+ 120 - 120
src/store/index.ts

@@ -1,136 +1,136 @@
-import type {IUser} from './user'
+import type { IUser } from './user'
 
 // 以下代码在build时自动移除,无需手动注释
 // #ifdef DEV
 localStorage.setItem('userInfo', JSON.stringify({
-  "user_id": "213558",
-  "user_name": "bozuser69",
-  "email": "无",
-  "lastlogintime": "2023-05-10 13:35:31",
-  "regdate": "2020-04-14 14:01:11",
-  "status": "0",
-  "user_role_id": "69",
-  "user_role_name": "区县管理员",
-  "user_avatar": {
-    "big": "https://openapi.dev.bozedu.net/template/default/static/img/avatar_teacher_big.png",
-    "middle": "https://openapi.dev.bozedu.net/template/default/static/img/avatar_teacher_middle.png",
-    "small": "https://openapi.dev.bozedu.net/template/default/static/img/avatar_teacher_small.png"
+  user_id: '213558',
+  user_name: 'bozuser69',
+  email: '无',
+  lastlogintime: '2023-05-10 13:35:31',
+  regdate: '2020-04-14 14:01:11',
+  status: '0',
+  user_role_id: '69',
+  user_role_name: '区县管理员',
+  user_avatar: {
+    big: 'https://openapi.dev.bozedu.net/template/default/static/img/avatar_teacher_big.png',
+    middle: 'https://openapi.dev.bozedu.net/template/default/static/img/avatar_teacher_middle.png',
+    small: 'https://openapi.dev.bozedu.net/template/default/static/img/avatar_teacher_small.png',
   },
-  "user_no": {"no_title": "学号", "no": ""},
-  "token": "f842MX83zJZkuqk8Q_blBD9kmZDaNkpzn70vbQkWvsWiqN9F63l4EXuwvfs_bjql3aSG9jkkBF08YOxGjL1cvM_a7_bk8gs",
-  "user_realname": "博智测试区县",
-  "user_phone": "",
-  "idcard": "",
-  "gender": "1",
-  "gender_char": "男",
-  "qq": "无",
-  "nationality": "",
-  "intro": "",
-  "address": "",
-  "education": "",
-  "area_info": {
-    "area_id1": "10",
-    "area_id2": "166",
-    "area_id3": "2074",
-    "area_id4": "0",
-    "area_id1_char": "江苏省",
-    "area_id2_char": "苏州市",
-    "area_id3_char": "相城区",
-    "area_id4_char": "",
-    "area_code1": "320000000000",
-    "area_code2": "320500000000",
-    "area_code3": "320507000000",
-    "area_code4": "",
-    "area_code_dist": "320507000000"
+  user_no: { no_title: '学号', no: '' },
+  token: 'f842MX83zJZkuqk8Q_blBD9kmZDaNkpzn70vbQkWvsWiqN9F63l4EXuwvfs_bjql3aSG9jkkBF08YOxGjL1cvM_a7_bk8gs',
+  user_realname: '博智测试区县',
+  user_phone: '',
+  idcard: '',
+  gender: '1',
+  gender_char: '男',
+  qq: '无',
+  nationality: '',
+  intro: '',
+  address: '',
+  education: '',
+  area_info: {
+    area_id1: '10',
+    area_id2: '166',
+    area_id3: '2074',
+    area_id4: '0',
+    area_id1_char: '江苏省',
+    area_id2_char: '苏州市',
+    area_id3_char: '相城区',
+    area_id4_char: '',
+    area_code1: '320000000000',
+    area_code2: '320500000000',
+    area_code3: '320507000000',
+    area_code4: '',
+    area_code_dist: '320507000000',
   },
-  "sm_info": {
-    "sm_id": "0",
-    "sm_name": "",
-    "adminid": "0",
-    "is_org": "0",
-    "up_org": "0",
-    "area_id1": "0",
-    "area_id2": "0",
-    "area_id3": "0",
-    "area_id4": "0",
-    "major_mode": "0",
-    "powers": {"vip_shiti": "1", "vip_sucai": "1", "vip_aicheck": "1"}
+  sm_info: {
+    sm_id: '0',
+    sm_name: '',
+    adminid: '0',
+    is_org: '0',
+    up_org: '0',
+    area_id1: '0',
+    area_id2: '0',
+    area_id3: '0',
+    area_id4: '0',
+    major_mode: '0',
+    powers: { vip_shiti: '1', vip_sucai: '1', vip_aicheck: '1' },
   },
-  "cm_info": [],
-  "first_cm_id": "",
-  "first_cm_name": "",
-  "related_desc": "全部",
-  "bind3rd": {"wechat": "0"},
-  "my_org": [],
-  "org_info": {
-    "org": null,
-    "org_id": null,
-    "telephone": "",
-    "telephone_short": "",
-    "is_org": "1",
-    "up_org": null,
-    "up_org_name": null,
-    "up_org_info": {"sm_id": "", "sm_name": ""}
+  cm_info: [],
+  first_cm_id: '',
+  first_cm_name: '',
+  related_desc: '全部',
+  bind3rd: { wechat: '0' },
+  my_org: [],
+  org_info: {
+    org: null,
+    org_id: null,
+    telephone: '',
+    telephone_short: '',
+    is_org: '1',
+    up_org: null,
+    up_org_name: null,
+    up_org_info: { sm_id: '', sm_name: '' },
   },
-  "pan": {"unit": "G", "size": "0", "used": "0.00", "desc": "无限制"},
-  "safe_tips": ["您的密码安全程度较低,请立即修改", "必须包含数字、字母大小写或者特殊字符,长度8位及以上"],
-  "update_center": "https://openapi.dev.bozedu.net",
-  "base_url": {
-    "aboutus": "https://openapi.dev.bozedu.net/aboutus",
-    "file": "https://openapi.dev.bozedu.net",
-    "vpn": "http://vpn.dev.bozedu.net",
-    "uc": "https://uc.dev.bozedu.net",
-    "yzy": "https://yzy.dev.bozedu.net",
-    "kzkt": "https://openapi.dev.bozedu.net",
-    "openapi": "https://openapi.dev.bozedu.net",
-    "site_zhkt_api": "http://120.26.51.195:8008",
-    "yxxt": "https://yxxt.dev.bozedu.net"
+  pan: { unit: 'G', size: '0', used: '0.00', desc: '无限制' },
+  safe_tips: ['您的密码安全程度较低,请立即修改', '必须包含数字、字母大小写或者特殊字符,长度8位及以上'],
+  update_center: 'https://openapi.dev.bozedu.net',
+  base_url: {
+    aboutus: 'https://openapi.dev.bozedu.net/aboutus',
+    file: 'https://openapi.dev.bozedu.net',
+    vpn: 'http://vpn.dev.bozedu.net',
+    uc: 'https://uc.dev.bozedu.net',
+    yzy: 'https://yzy.dev.bozedu.net',
+    kzkt: 'https://openapi.dev.bozedu.net',
+    openapi: 'https://openapi.dev.bozedu.net',
+    site_zhkt_api: 'http://120.26.51.195:8008',
+    yxxt: 'https://yxxt.dev.bozedu.net',
   },
-  "role_system": {
-    "kzkt": {
-      "code": "kzkt",
-      "name": "空中课堂",
-      "icon": "",
-      "cate": "1",
-      "type": "1",
-      "url": "https://openapi.dev.bozedu.net"
+  role_system: {
+    kzkt: {
+      code: 'kzkt',
+      name: '空中课堂',
+      icon: '',
+      cate: '1',
+      type: '1',
+      url: 'https://openapi.dev.bozedu.net',
     },
-    "yzy": {
-      "code": "yzy",
-      "name": "作业系统",
-      "icon": "",
-      "cate": "1",
-      "type": "1",
-      "url": "https://yzy.dev.bozedu.net"
+    yzy: {
+      code: 'yzy',
+      name: '作业系统',
+      icon: '',
+      cate: '1',
+      type: '1',
+      url: 'https://yzy.dev.bozedu.net',
+    },
+    zhkt: {
+      code: 'zhkt',
+      name: '智慧课堂',
+      icon: '',
+      cate: '1',
+      type: '2',
+      url: 'http://120.26.51.195:8008/desadmin.php',
     },
-    "zhkt": {
-      "code": "zhkt",
-      "name": "智慧课堂",
-      "icon": "",
-      "cate": "1",
-      "type": "2",
-      "url": "http://120.26.51.195:8008/desadmin.php"
-    }
   },
-  "user_score": "70",
-  "product": ["课堂", "直播", "作业"],
-  "app_url": {
-    "A119": "https://qqyxt.m.dev.bozedu.net/page/course/tskc_more.html",
-    "A120": "https://qqyxt.m.dev.bozedu.net/page/my/msg_hybrid.html?id=31",
-    "A121": "https://qqyxt.m.dev.bozedu.net/page/parent/msg.html",
-    "A122": "https://qqyxt.m.dev.bozedu.net/page/my/integral_hybrid.html",
-    "A123": "https://qqyxt.m.dev.bozedu.net/ktfx/xqbg.html",
-    "A124": "https://qqyxt.m.dev.bozedu.net/page/my/footPrint.html",
-    "A125": "https://qqyxt.m.dev.bozedu.net/page/my/intergralMall.html",
-    "A126": "https://openapi.dev.bozedu.net/component/ebook_main/public",
-    "A127": "https://qqyxt.m.dev.bozedu.net/Course_registration/transfer.html?v=1",
-    "A128": "https://qqyxt.m.dev.bozedu.net/Course_registration/transfer.html?type=course_after_service",
-    "A129": "https://qqyxt.m.dev.bozedu.net/ktfx/xqbg.html?tab=1",
-    "A130": "https://qqyxt.m.dev.bozedu.net/ktfx/xqbg.html?tab=2",
-    "A131": "https://qqyxt.m.dev.bozedu.net/ktfx/xqbg.html?tab=3",
-    "A132": "https://qqyxt.m.dev.bozedu.net/ktfx/xqbg.html?tab=4"
+  user_score: '70',
+  product: ['课堂', '直播', '作业'],
+  app_url: {
+    A119: 'https://qqyxt.m.dev.bozedu.net/page/course/tskc_more.html',
+    A120: 'https://qqyxt.m.dev.bozedu.net/page/my/msg_hybrid.html?id=31',
+    A121: 'https://qqyxt.m.dev.bozedu.net/page/parent/msg.html',
+    A122: 'https://qqyxt.m.dev.bozedu.net/page/my/integral_hybrid.html',
+    A123: 'https://qqyxt.m.dev.bozedu.net/ktfx/xqbg.html',
+    A124: 'https://qqyxt.m.dev.bozedu.net/page/my/footPrint.html',
+    A125: 'https://qqyxt.m.dev.bozedu.net/page/my/intergralMall.html',
+    A126: 'https://openapi.dev.bozedu.net/component/ebook_main/public',
+    A127: 'https://qqyxt.m.dev.bozedu.net/Course_registration/transfer.html?v=1',
+    A128: 'https://qqyxt.m.dev.bozedu.net/Course_registration/transfer.html?type=course_after_service',
+    A129: 'https://qqyxt.m.dev.bozedu.net/ktfx/xqbg.html?tab=1',
+    A130: 'https://qqyxt.m.dev.bozedu.net/ktfx/xqbg.html?tab=2',
+    A131: 'https://qqyxt.m.dev.bozedu.net/ktfx/xqbg.html?tab=3',
+    A132: 'https://qqyxt.m.dev.bozedu.net/ktfx/xqbg.html?tab=4',
   },
-  "cpm_access_level": "3"
+  cpm_access_level: '3',
 }))
 // #endif
 

+ 7 - 5
vite.config.ts

@@ -11,10 +11,11 @@ import AutoImport from 'unplugin-auto-import/vite'
 import VueMacros from 'unplugin-vue-macros/vite'
 import Icons from 'unplugin-icons/vite'
 import IconsResolver from 'unplugin-icons/resolver'
+import ConditionalCompile from './plugins/vite-plugin-conditional-compile'
 
-export default defineConfig(({command}) => {
+export default defineConfig(({ command }) => {
   const cfg = {
-    base:'',
+    base: '',
     resolve: {
       alias: {
         '~/': `${path.resolve(__dirname, 'src')}/`,
@@ -23,6 +24,7 @@ export default defineConfig(({command}) => {
       },
     },
     plugins: [
+      ConditionalCompile(),
       VueMacros({
         plugins: {
           vue: Vue({
@@ -68,11 +70,11 @@ export default defineConfig(({command}) => {
       environment: 'jsdom',
     },
   }
-  if(command === 'build') {
+  if (command === 'build') {
     cfg.base = '/webapps/page/liankao/'
     return cfg
-  } else {
+  }
+  else {
     return cfg
   }
-
 })