Parcourir la source

feat: add platform and version management UI

DESKTOP-HN5QP3V\Administrator il y a 2 mois
Parent
commit
80ea2a650e

+ 17 - 1
mock/role/index.mock.ts

@@ -3,7 +3,7 @@ import { SUCCESS_CODE } from '@/constants'
 
 const timeout = 1000
 
-const adminList = [
+const adminList: any[] = [
   {
     path: '/version',
     name: 'Version',
@@ -54,6 +54,15 @@ const adminList = [
           title: 'router.version_test',
           noCache: true
         }
+      },
+      {
+        path: 'config',
+        component: 'views/Version/VersionConfig',
+        name: 'VersionConfig',
+        meta: {
+          title: '加载配置',
+          noCache: true
+        }
       }
     ]
   },
@@ -78,6 +87,13 @@ const adminList = [
         }
       }
     ]
+  },
+  {
+    path: '/platform',
+    component: '#',
+    name: 'Platform',
+    meta: { title: '平台管理', icon: 'ep:monitor', alwaysShow: true },
+    children: [{ path: 'manage', component: 'views/Platform/PlatformManage', name: 'PlatformManage', meta: { title: '平台列表', noCache: true } }]
   }
 ]
 

+ 6 - 0
src/api/platform/index.ts

@@ -0,0 +1,6 @@
+import request from '@/axios'
+export type PlatformData = { id: any; name: string; code: string; status: boolean }
+export const getPlatformListApi = () => request.get({ url: '/web/v1/platform/list' })
+export const addPlatformApi = (data: Partial<PlatformData>) => request.post({ url: '/web/v1/platform', data })
+export const editPlatformApi = (data: Partial<PlatformData>) => request.put({ url: '/web/v1/platform', data })
+export const delPlatformApi = (id: string) => request.post({ url: '/web/v1/platform/delete', data: { id } })

+ 3 - 0
src/api/version/index.ts

@@ -21,6 +21,9 @@ export const syncVersionApi = (): Promise<IResponse> => {
   return request.post({ url: `/web/v1/version/reload` })
 }
 
+export const getVersionConfigListApi = (params: any) => request.get({ url: '/web/v1/version/configs', params })
+export const saveVersionConfigApi = (data: any): Promise<IResponse> => request.post({ url: '/web/v1/version/config', data })
+
 export const test1VersionApi = (data) => {
   return request.post({ url: `/api/v1/version/check`, data })
 }

+ 10 - 0
src/api/version/types.ts

@@ -7,6 +7,7 @@ export type TableData = {
 
 export type VersionData = {
   id: any
+  platform: string
   envVersion: string
   version: string
   cdn: string
@@ -15,6 +16,15 @@ export type VersionData = {
   default: boolean
 }
 
+export type VersionConfigData = {
+  id: any
+  platform: string
+  version: string
+  value: string
+  envVersions: string[]
+  external: boolean
+}
+
 export type HotVersionData = {
   id: any
   proj: string

+ 44 - 0
src/components/ChannelSwitcher/ChannelSwitcher.vue

@@ -0,0 +1,44 @@
+<script setup lang="ts">
+import { onMounted, ref, watch } from 'vue'
+import { ElOption, ElSelect } from 'element-plus'
+import { getChannelListApi } from '@/api/channel'
+import type { ChannelData } from '@/api/channel/types'
+const channels = ref<ChannelData[]>([])
+const current = ref(localStorage.getItem('currentChannel') || '')
+const load = async () => {
+  const res = await getChannelListApi({ pageIndex: 1, pageSize: 100 })
+  const data = res?.data?.list ?? res?.data
+  channels.value = Array.isArray(data) ? data.filter((item) => item?.status !== false).sort((a, b) => (a.code === 'bb' ? -1 : b.code === 'bb' ? 1 : 0)) : []
+  if (channels.value.length && (!current.value || !channels.value.some((item) => item.code === current.value))) current.value = channels.value[0].code
+}
+watch(current, (value) => { if (value) localStorage.setItem('currentChannel', value); window.dispatchEvent(new CustomEvent('channel-change', { detail: value })) })
+onMounted(load)
+window.addEventListener('channel-list-updated', load)
+</script>
+<template>
+  <div class="channel-switcher">
+    <div class="channel-heading">工作区渠道</div>
+    <ElSelect v-model="current" placeholder="选择渠道" class="channel-select">
+      <ElOption v-for="item in channels" :key="item.code" :label="item.name" :value="item.code" />
+    </ElSelect>
+  </div>
+</template>
+
+<style scoped>
+.channel-switcher {
+  box-sizing: border-box;
+  display: block;
+  height: 72px;
+  margin: 0;
+  padding: 10px 24px 9px;
+  background: #102a43 !important;
+  border: 0;
+  border-radius: 0;
+}
+.channel-heading { margin-bottom: 5px; color: rgba(255, 255, 255, 0.68); font-size: 11px; line-height: 14px; }
+.channel-select { width: 100%; }
+.channel-select :deep(.el-select__wrapper) { min-height: 34px; padding: 0 8px; background: #102a43 !important; border-radius: 3px; box-shadow: none !important; }
+.channel-select :deep(.el-select__wrapper:hover), .channel-select :deep(.el-select__wrapper.is-focused) { background: #173b59 !important; }
+.channel-select :deep(.el-select__selected-item) { color: #fff; font-size: 14px; }
+.channel-select :deep(.el-select__caret) { color: rgba(255, 255, 255, 0.72); }
+</style>

+ 2 - 0
src/layout/components/useRenderLayout.tsx

@@ -8,6 +8,7 @@ import AppView from './AppView.vue'
 import ToolHeader from './ToolHeader.vue'
 import { ElScrollbar } from 'element-plus'
 import { useDesign } from '@/hooks/web/useDesign'
+import ChannelSwitcher from '@/components/ChannelSwitcher/ChannelSwitcher.vue'
 
 const { getPrefixCls } = useDesign()
 
@@ -58,6 +59,7 @@ export const useRenderLayout = () => {
               style="transition: all var(--transition-time-02);"
             ></Logo>
           ) : undefined}
+          <ChannelSwitcher />
           <Menu class={[{ '!h-[calc(100%-var(--logo-height))]': logo.value }]}></Menu>
         </div>
         <div

+ 12 - 1
src/router/index.ts

@@ -85,7 +85,8 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [
               title: t('router.version_server'),
               noCache: true
             }
-          } /*,
+          },
+          /*,
           {
             path: 'version_client',
             name: 'VersionClient',
@@ -105,6 +106,12 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [
           title: t('router.version_test'),
           noCache: true
         }
+      },
+      {
+        path: 'config',
+        name: 'VersionConfig',
+        component: () => import('@/views/Version/VersionConfig.vue'),
+        meta: { title: '加载配置', noCache: true }
       }
     ]
   },
@@ -130,6 +137,10 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [
       }
     ]
   }
+  ,{
+    path: '/platform', name: 'Platform', component: Layout, redirect: '/platform/manage', meta: { title: '平台管理', icon: 'ep:monitor', alwaysShow: true },
+    children: [{ path: 'manage', name: 'PlatformManage', component: () => import('@/views/Platform/PlatformManage.vue'), meta: { title: '平台列表', noCache: true } }]
+  }
 ]
 
 const router = createRouter({

+ 1 - 0
src/views/Channel/ChannelManage.vue

@@ -113,6 +113,7 @@ const getList = async () => {
     })
   if (res?.data) {
     channelList.value = res.data.list || []
+    window.dispatchEvent(new CustomEvent('channel-list-updated'))
   }
 }
 

+ 24 - 0
src/views/Platform/PlatformManage.vue

@@ -0,0 +1,24 @@
+<script setup lang="tsx">
+import { ref } from 'vue'
+import { ElButton, ElInput, ElMessage, ElMessageBox, ElSwitch } from 'element-plus'
+import { ContentWrap } from '@/components/ContentWrap'
+import { Table, TableColumn } from '@/components/Table'
+import { BaseButton } from '@/components/Button'
+import { getPlatformListApi, addPlatformApi, editPlatformApi, delPlatformApi, PlatformData } from '@/api/platform'
+const list = ref<PlatformData[]>([])
+const name = ref('')
+const code = ref('')
+const load = async () => { const res = await getPlatformListApi(); list.value = res?.data?.data ?? res?.data ?? [] }
+const add = async () => { if (!name.value.trim() || !code.value.trim()) { ElMessage.warning('平台名称和编码不能为空'); return }; await addPlatformApi({ name: name.value, code: code.value, status: true }); name.value = ''; code.value = ''; load() }
+const columns: TableColumn[] = [
+  { field: 'name', label: '平台名称' },
+  { field: 'code', label: '平台编码' },
+  { field: 'status', label: '状态', slots: { default: (d) => <ElSwitch modelValue={d.row.status} onUpdate:modelValue={(v) => { d.row.status = v; editPlatformApi({ id: d.row.id?.id || d.row.id, status: Boolean(v) }) }} /> } },
+  { field: 'action', label: '操作', width: 100, slots: { default: (d) => <BaseButton type="danger" onClick={() => ElMessageBox.confirm('确认删除该平台?').then(async () => { await delPlatformApi(d.row.id?.id || d.row.id); load() }).catch(() => {})}>删除</BaseButton> } }
+]
+load()
+</script>
+<template>
+  <ContentWrap><div class="flex gap-2"><ElInput v-model="name" placeholder="平台名称,如微信" style="width:220px" /><ElInput v-model="code" placeholder="平台编码,如 wx" style="width:180px" /><ElButton type="primary" @click="add">新增平台</ElButton></div></ContentWrap>
+  <ContentWrap><Table :columns="columns" :data="list" row-key="id" /></ContentWrap>
+</template>

+ 27 - 37
src/views/Version/Test.vue

@@ -1,13 +1,12 @@
 <script setup lang="tsx">
 import {ElButton, ElInput, ElMessage, ElOption, ElSelect} from 'element-plus'
 import { ContentWrap } from '@/components/ContentWrap'
-import {reactive, ref, watch} from 'vue'
+import {reactive, ref, onMounted, watch} from 'vue'
 import {test1VersionApi, test2VersionApi} from '@/api/version'
-import type {ChannelData} from "@/api/channel/types";
-import {getChannelListApi} from "@/api/channel";
+import { getPlatformListApi, type PlatformData } from '@/api/platform'
 
-const channelOptions = ref<ChannelData[]>([])
-const selectedChannel = ref<string>('')
+const platformOptions = ref<PlatformData[]>([])
+const selectedPlatform = ref<string>('')
 
 const envVersionOptions = [
   { label: '不传', value: '' },
@@ -15,44 +14,37 @@ const envVersionOptions = [
   { label: '体验版', value: 'trial' }
 ]
 
-const getChannelList = async () => {
+const getPlatformList = async () => {
   try {
-    const res = await getChannelListApi({ pageIndex: 1, pageSize: 100 })
-    const list = res?.data?.list ?? (Array.isArray(res?.data) ? res.data : [])
-    channelOptions.value = list.filter((c) => c && c.status !== false)
+    const res = await getPlatformListApi()
+    const list = res?.data?.data ?? res?.data ?? []
+    platformOptions.value = Array.isArray(list) ? list.filter((item) => item && item.status !== false) : []
   } catch (e) {
-    console.warn('[渠道列表] 请求失败:', e)
-    channelOptions.value = []
+    console.warn('[平台列表] 请求失败:', e)
+    platformOptions.value = []
   }
 }
 
-getChannelList()
+onMounted(getPlatformList)
 
 const form = reactive({
-  channel: '',
+  platform: '',
   version: '',
   envVersion: '',
   testarea: ''
 })
 
-watch(selectedChannel, (val) => {
-  form.channel = val
-})
+watch(selectedPlatform, (value) => { form.platform = value })
 
 const testApi1 = async () => {
-  if (!form.version.trim()) {
-    ElMessage.error('版本号不能为空')
-    return
-  }
-
-  if (!form.channel.trim() && form.version.trim() > "1.0.67") {
-    ElMessage.error('渠道不能为空')
+  if (!form.platform.trim()) {
+    ElMessage.error('平台不能为空')
     return
   }
 
   const res = await test1VersionApi({
-    version: form.version,
-    channel: form.channel,
+    version: form.version.trim(),
+    platform: form.platform,
     envVersion: form.envVersion
   })
     .catch(() => {})
@@ -63,7 +55,11 @@ const testApi1 = async () => {
 }
 
 const testApi2 = async () => {
-  const res = await test2VersionApi({ channel: form.channel })
+  if (!form.platform.trim()) {
+    ElMessage.error('平台不能为空')
+    return
+  }
+  const res = await test2VersionApi({ platform: form.platform })
     .catch(() => {})
     .finally(() => {})
   form.testarea = ''
@@ -73,21 +69,15 @@ const testApi2 = async () => {
 
 <template>
   <ContentWrap>
-    <span style="font-size: 14px; color: var(--el-text-color-regular)">
-            {{ '渠道' }}:
-          </span>
-    <ElSelect
-        v-model="selectedChannel"
-        placeholder="选择渠道"
-        style="width: 180px"
-    >
-      <ElOption v-for="c in channelOptions" :key="c.code" :label="c.name" :value="c.code" />
+    <span style="font-size: 14px; color: var(--el-text-color-regular)">平台筛选:</span>
+    <ElSelect v-model="selectedPlatform" placeholder="选择平台" style="width: 180px">
+      <ElOption v-for="item in platformOptions" :key="item.code" :label="item.name" :value="item.code" />
     </ElSelect>
     <ElInput
       id="version"
       v-model="form.version"
       style="width: 120px; margin-right: 20px"
-      placeholder="输入版本号"
+      placeholder="版本号(可选)"
     />
     <ElSelect
       id="envVersion"
@@ -103,7 +93,7 @@ const testApi2 = async () => {
       />
     </ElSelect>
     <ElButton type="primary" @click="() => testApi1()">
-      {{ '按版本号检查' }}
+      {{ '检查版本' }}
     </ElButton>
     <ElButton type="primary" @click="() => testApi2()">
       {{ '获取所有版本' }}

+ 63 - 0
src/views/Version/VersionConfig.vue

@@ -0,0 +1,63 @@
+<script setup lang="tsx">
+import { onMounted, ref } from 'vue'
+import { ElButton, ElOption, ElSelect, ElSwitch, ElTabs, ElTabPane } from 'element-plus'
+import { ContentWrap } from '@/components/ContentWrap'
+import { Table, TableColumn } from '@/components/Table'
+import { getVersionConfigListApi, saveVersionConfigApi } from '@/api/version'
+import { getPlatformListApi, type PlatformData } from '@/api/platform'
+
+const configType = ref<'abVer' | 'md5'>('abVer')
+const configList = ref<any[]>([])
+const platformOptions = ref<PlatformData[]>([])
+const selectedPlatform = ref('')
+
+const load = async () => {
+  const res = await getVersionConfigListApi({ type: configType.value, platform: selectedPlatform.value || undefined })
+  const data = res?.data?.data ?? res?.data
+  configList.value = Array.isArray(data) ? data : []
+}
+
+const save = async (row: any, changes: any) => {
+  await saveVersionConfigApi({ type: configType.value, id: row.id?.id || row.id, ...changes })
+  load()
+}
+
+const columns: TableColumn[] = [
+  { field: 'platform', label: '平台', width: 220, slots: { default: (data) => data.row.platform || '历史数据(未标记平台)' } },
+  { field: 'version', label: '配置版本', width: 180 },
+  { field: 'value', label: '配置值', showOverflowTooltip: true },
+  { field: 'envVersions', label: '生效环境', width: 300, slots: { default: (data) => <ElSelect modelValue={data.row.envVersions?.length ? data.row.envVersions : ['release', 'trial']} multiple style="width: 220px" onUpdate:modelValue={(value) => save(data.row, { envVersions: value })}><ElOption label="正式服" value="release" /><ElOption label="提审服" value="trial" /></ElSelect> } },
+  { field: 'external', label: '是否对外', width: 180, slots: { default: (data) => <ElSwitch modelValue={data.row.external} onUpdate:modelValue={(value) => save(data.row, { external: Boolean(value) })} /> } }
+]
+
+const loadPlatforms = async () => {
+  const res = await getPlatformListApi()
+  const data = res?.data?.data ?? res?.data ?? []
+  platformOptions.value = Array.isArray(data) ? data.filter((item) => item.status !== false) : []
+}
+
+onMounted(() => { loadPlatforms(); load() })
+</script>
+
+<template>
+  <ContentWrap class="config-panel">
+    <ElTabs v-model="configType" type="card" @tab-change="load">
+      <ElTabPane label="abVer" name="abVer" />
+      <ElTabPane label="md5" name="md5" />
+    </ElTabs>
+    <div style="display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin: -4px 0 12px">
+      <span>平台筛选:</span>
+      <ElSelect v-model="selectedPlatform" placeholder="全部平台" clearable style="width: 180px" @change="load">
+        <ElOption v-for="item in platformOptions" :key="item.code" :label="item.name" :value="item.code" />
+      </ElSelect>
+      <ElButton type="primary" @click="load">查询</ElButton>
+    </div>
+    <Table :columns="columns" :data="configList" />
+  </ContentWrap>
+</template>
+
+<style scoped>
+.config-panel {
+  background: #f5f7fa;
+}
+</style>

+ 38 - 56
src/views/Version/VersionServer.vue

@@ -24,23 +24,18 @@ import {
   newVersionApi,
   syncVersionApi
 } from '@/api/version'
-import { getChannelListApi } from '@/api/channel'
-import type { ChannelData } from '@/api/channel/types'
+import { getPlatformListApi } from '@/api/platform'
+import type { PlatformData } from '@/api/platform'
 
 interface Params {
   pageIndex?: number
   pageSize?: number
-  channel?: string
+  platform?: string
   envVersion?: string
 }
 
 const { t } = useI18n()
 
-const getChannelLabel = (code: string) => {
-  const c = channelOptions.value.find((x) => x.code === code)
-  return c ? c.name : code
-}
-
 const envVersionOptions = [
   { label: '正式服', value: 'release' },
   { label: '体验版', value: 'trial' }
@@ -57,9 +52,8 @@ const columns: TableColumn[] = [
     label: t('version_server.title')
   },
   {
-    field: 'channel',
-    label: t('version_server.channel'),
-    formatter: (row) => getChannelLabel(row.channel)
+    field: 'platform',
+    label: '平台'
   },
   {
     field: 'envVersion',
@@ -118,37 +112,35 @@ const loading = ref(true)
 const drawerText = ref('')
 
 const versionDataList = ref<VersionData[]>([])
-const selectedChannel = ref<string>('')
+const selectedPlatform = ref<string>('')
 const selectedEnvVersion = ref<string>('')
 
-// 渠道选项:从后端获取
-const channelOptions = ref<ChannelData[]>([])
-
-const getChannelList = async () => {
-  try {
-    const res = await getChannelListApi({ pageIndex: 1, pageSize: 100 })
-    const list = res?.data?.list ?? (Array.isArray(res?.data) ? res.data : [])
-    channelOptions.value = list.filter((c) => c && c.status !== false)
-  } catch (e) {
-    console.warn('[渠道列表] 请求失败:', e)
-    channelOptions.value = []
-  }
-}
+const platformOptions = ref<PlatformData[]>([])
 
-const applyChannelFilter = () => {
+const applyFilters = () => {
   getVersionList({
     pageIndex: 1,
     pageSize: 10,
-    channel: selectedChannel.value,
+    platform: selectedPlatform.value,
     envVersion: selectedEnvVersion.value
   })
 }
 
+const getPlatformList = async () => {
+  try {
+    const res = await getPlatformListApi()
+    const list = res?.data?.data ?? res?.data ?? []
+    platformOptions.value = Array.isArray(list) ? list.filter((item) => item && item.status !== false) : []
+  } catch {
+    platformOptions.value = []
+  }
+}
+
 const form = reactive({
   type: 'new',
   data: {
     id: '',
-    channel: '',
+    platform: '',
     envVersion: 'release',
     version: '',
     name: '',
@@ -160,7 +152,7 @@ const form = reactive({
 
 const formReset = () => {
   form.data.id = ''
-  form.data.channel = ''
+  form.data.platform = ''
   form.data.envVersion = 'release'
   form.data.version = ''
   form.data.name = ''
@@ -210,8 +202,11 @@ const editVersion = async (params) => {
     })
 }
 
-getChannelList()
-getVersionList()
+getPlatformList()
+getVersionList({
+  pageIndex: 1,
+  pageSize: 10
+})
 
 const updateDefaultStatus = async (row: VersionData, val) => {
   row.default = val
@@ -253,7 +248,6 @@ const syncVersion = async () => {
 }
 
 const actionFn = (type: string, data: any) => {
-  getChannelList()
   if (type == 'new') {
     formReset()
     form.type = 'new'
@@ -262,7 +256,7 @@ const actionFn = (type: string, data: any) => {
   if (type == 'edit') {
     form.type = 'edit'
     drawerText.value = t('version_server.edit')
-    form.data.channel = data.channel
+    form.data.platform = data.platform || ''
     form.data.envVersion = data.envVersion || 'release'
     form.data.id = data.id.id
     form.data.cdn = data.cdn
@@ -297,17 +291,17 @@ const closeDrawer = () => {
         </ElButton>
         <div style="display: flex; align-items: center; gap: 8px">
           <span style="font-size: 14px; color: var(--el-text-color-regular)">
-            {{ t('version_server.channelSelect') }}:
+            平台筛选:
           </span>
           <ElSelect
-            v-model="selectedChannel"
-            :placeholder="t('version_server.channelSelect')"
+            v-model="selectedPlatform"
+            placeholder="选择平台"
             style="width: 180px"
           >
-            <ElOption :label="t('version_server.allChannels')" value="" />
-            <ElOption v-for="c in channelOptions" :key="c.code" :label="c.name" :value="c.code" />
+            <ElOption label="全部平台" value="" />
+            <ElOption v-for="item in platformOptions" :key="item.code" :label="item.name" :value="item.code" />
           </ElSelect>
-          <ElButton type="primary" @click="applyChannelFilter">
+          <ElButton type="primary" @click="applyFilters">
             {{ t('version_server.confirm') }}
           </ElButton>
         </div>
@@ -356,26 +350,14 @@ const closeDrawer = () => {
       <span class="text-16px font-700">{{ drawerText }}</span>
     </template>
     <ElForm :model="form" label-width="auto" style="max-width: 600px">
-      <ElFormItem :label="t('version_server.channel')" required>
-        <ElSelect
-          v-model="form.data.channel"
-          :placeholder="
-            channelOptions.length
-              ? t('version_server.channelSelect')
-              : t('version_server.channelEmpty')
-          "
-          style="width: 100%"
-          :disabled="form.type == 'edit'"
-        >
-          <ElOption v-for="c in channelOptions" :key="c.code" :label="c.name" :value="c.code" />
-        </ElSelect>
-        <div v-if="!channelOptions.length" class="el-form-item__error">
-          {{ t('version_server.channelEmptyTip') }}
-        </div>
-      </ElFormItem>
       <ElFormItem :label="t('version_server.title')">
         <ElInput v-model="form.data.name" />
       </ElFormItem>
+      <ElFormItem label="平台" required>
+        <ElSelect v-model="form.data.platform" placeholder="选择平台" style="width: 100%">
+          <ElOption v-for="item in platformOptions" :key="item.code" :label="item.name" :value="item.code" />
+        </ElSelect>
+      </ElFormItem>
       <ElFormItem :label="t('version_server.envVersion')" required>
         <ElSelect v-model="form.data.envVersion" style="width: 100%">
           <ElOption