Commit e187e7a016453e98a223d9721283e1c4c95b2251
1 parent
0a6d93fe
fix: tenant package select
Showing
2 changed files
with
42 additions
and
38 deletions
yudao-ui-admin-vue3/src/views/system/tenant/index.vue
| ... | ... | @@ -19,10 +19,10 @@ |
| 19 | 19 | @click="handleExport()" |
| 20 | 20 | /> |
| 21 | 21 | </template> |
| 22 | - <template #accountCount="{ row }"> | |
| 22 | + <template #accountCount_default="{ row }"> | |
| 23 | 23 | <el-tag> {{ row.accountCount }} </el-tag> |
| 24 | 24 | </template> |
| 25 | - <template #packageId="{ row }"> | |
| 25 | + <template #packageId_default="{ row }"> | |
| 26 | 26 | <el-tag v-if="row.packageId === 0" type="danger">系统租户</el-tag> |
| 27 | 27 | <el-tag v-else type="success"> {{ getPackageName(row.packageId) }} </el-tag> |
| 28 | 28 | </template> |
| ... | ... | @@ -58,18 +58,7 @@ |
| 58 | 58 | :schema="allSchemas.formSchema" |
| 59 | 59 | :rules="rules" |
| 60 | 60 | ref="formRef" |
| 61 | - > | |
| 62 | - <template #packageId> | |
| 63 | - <el-select v-model="tenantPackageId"> | |
| 64 | - <el-option | |
| 65 | - v-for="item in tenantPackageOptions" | |
| 66 | - :key="item.id" | |
| 67 | - :label="item.name" | |
| 68 | - :value="item.id" | |
| 69 | - /> | |
| 70 | - </el-select> | |
| 71 | - </template> | |
| 72 | - </Form> | |
| 61 | + /> | |
| 73 | 62 | <!-- 对话框(详情) --> |
| 74 | 63 | <Descriptions |
| 75 | 64 | v-if="actionType === 'detail'" |
| ... | ... | @@ -97,16 +86,15 @@ |
| 97 | 86 | </XModal> |
| 98 | 87 | </template> |
| 99 | 88 | <script setup lang="ts" name="Tenant"> |
| 100 | -import { ref, unref, onMounted } from 'vue' | |
| 89 | +import { ref, unref } from 'vue' | |
| 101 | 90 | import { useI18n } from '@/hooks/web/useI18n' |
| 102 | 91 | import { useMessage } from '@/hooks/web/useMessage' |
| 103 | 92 | import { useVxeGrid } from '@/hooks/web/useVxeGrid' |
| 104 | 93 | import { VxeGridInstance } from 'vxe-table' |
| 105 | -import { ElTag, ElSelect, ElOption } from 'element-plus' | |
| 94 | +import { ElTag } from 'element-plus' | |
| 106 | 95 | import { FormExpose } from '@/components/Form' |
| 107 | 96 | import * as TenantApi from '@/api/system/tenant' |
| 108 | -import { rules, allSchemas } from './tenant.data' | |
| 109 | -import { getTenantPackageList, TenantPackageVO } from '@/api/system/tenantPackage' | |
| 97 | +import { rules, allSchemas, tenantPackageOption } from './tenant.data' | |
| 110 | 98 | |
| 111 | 99 | const { t } = useI18n() // 国际化 |
| 112 | 100 | const message = useMessage() // 消息弹窗 |
| ... | ... | @@ -125,17 +113,10 @@ const dialogVisible = ref(false) // 是否显示弹出层 |
| 125 | 113 | const dialogTitle = ref('edit') // 弹出层标题 |
| 126 | 114 | const formRef = ref<FormExpose>() // 表单 Ref |
| 127 | 115 | const detailRef = ref() // 详情 Ref |
| 128 | -const tenantPackageId = ref() // 套餐 | |
| 129 | -const tenantPackageOptions = ref<TenantPackageVO[]>([]) //套餐列表 | |
| 130 | - | |
| 131 | -const getTenantPackageOptions = async () => { | |
| 132 | - const res = await getTenantPackageList() | |
| 133 | - tenantPackageOptions.value.push(...res) | |
| 134 | -} | |
| 135 | 116 | const getPackageName = (packageId: number) => { |
| 136 | - for (let item of tenantPackageOptions.value) { | |
| 137 | - if (item.id === packageId) { | |
| 138 | - return item.name | |
| 117 | + for (let item of tenantPackageOption) { | |
| 118 | + if (item.value === packageId) { | |
| 119 | + return item.label | |
| 139 | 120 | } |
| 140 | 121 | } |
| 141 | 122 | return '未知套餐' |
| ... | ... | @@ -151,7 +132,6 @@ const setDialogTile = (type: string) => { |
| 151 | 132 | // 新增操作 |
| 152 | 133 | const handleCreate = () => { |
| 153 | 134 | // 重置表单 |
| 154 | - tenantPackageId.value = '' | |
| 155 | 135 | setDialogTile('create') |
| 156 | 136 | } |
| 157 | 137 | |
| ... | ... | @@ -160,7 +140,6 @@ const handleUpdate = async (rowId: number) => { |
| 160 | 140 | setDialogTile('update') |
| 161 | 141 | // 设置数据 |
| 162 | 142 | const res = await TenantApi.getTenantApi(rowId) |
| 163 | - tenantPackageId.value = res.packageId | |
| 164 | 143 | unref(formRef)?.setValues(res) |
| 165 | 144 | } |
| 166 | 145 | |
| ... | ... | @@ -168,7 +147,6 @@ const handleUpdate = async (rowId: number) => { |
| 168 | 147 | const handleDetail = async (rowId: number) => { |
| 169 | 148 | // 设置数据 |
| 170 | 149 | const res = await TenantApi.getTenantApi(rowId) |
| 171 | - tenantPackageId.value = res.packageId | |
| 172 | 150 | detailRef.value = res |
| 173 | 151 | setDialogTile('detail') |
| 174 | 152 | } |
| ... | ... | @@ -193,7 +171,6 @@ const submitForm = async () => { |
| 193 | 171 | // 提交请求 |
| 194 | 172 | try { |
| 195 | 173 | const data = unref(formRef)?.formModel as TenantApi.TenantVO |
| 196 | - data.packageId = tenantPackageId.value | |
| 197 | 174 | if (actionType.value === 'create') { |
| 198 | 175 | await TenantApi.createTenantApi(data) |
| 199 | 176 | message.success(t('common.createSuccess')) |
| ... | ... | @@ -211,9 +188,4 @@ const submitForm = async () => { |
| 211 | 188 | } |
| 212 | 189 | }) |
| 213 | 190 | } |
| 214 | - | |
| 215 | -// ========== 初始化 ========== | |
| 216 | -onMounted(async () => { | |
| 217 | - await getTenantPackageOptions() | |
| 218 | -}) | |
| 219 | 191 | </script> | ... | ... |
yudao-ui-admin-vue3/src/views/system/tenant/tenant.data.ts
| ... | ... | @@ -3,7 +3,23 @@ import { useI18n } from '@/hooks/web/useI18n' |
| 3 | 3 | import { required } from '@/utils/formRules' |
| 4 | 4 | import { DICT_TYPE } from '@/utils/dict' |
| 5 | 5 | import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas' |
| 6 | +import { getTenantPackageList, TenantPackageVO } from '@/api/system/tenantPackage' | |
| 7 | +import { ComponentOptions } from '@/types/components' | |
| 6 | 8 | const { t } = useI18n() // 国际化 |
| 9 | +export const tenantPackageOption: ComponentOptions[] = [] | |
| 10 | +const getTenantPackageOptions = async () => { | |
| 11 | + const res = await getTenantPackageList() | |
| 12 | + res.forEach((tenantPackage: TenantPackageVO) => { | |
| 13 | + tenantPackageOption.push({ | |
| 14 | + key: tenantPackage.id, | |
| 15 | + value: tenantPackage.id, | |
| 16 | + label: tenantPackage.name | |
| 17 | + }) | |
| 18 | + }) | |
| 19 | + | |
| 20 | + return tenantPackageOption | |
| 21 | +} | |
| 22 | +getTenantPackageOptions() | |
| 7 | 23 | |
| 8 | 24 | // 表单校验 |
| 9 | 25 | export const rules = reactive({ |
| ... | ... | @@ -30,7 +46,18 @@ const crudSchemas = reactive<VxeCrudSchema>({ |
| 30 | 46 | }, |
| 31 | 47 | { |
| 32 | 48 | title: '租户套餐', |
| 33 | - field: 'packageId' | |
| 49 | + field: 'packageId', | |
| 50 | + table: { | |
| 51 | + slots: { | |
| 52 | + default: 'packageId_default' | |
| 53 | + } | |
| 54 | + }, | |
| 55 | + form: { | |
| 56 | + component: 'Select', | |
| 57 | + componentProps: { | |
| 58 | + options: tenantPackageOption | |
| 59 | + } | |
| 60 | + } | |
| 34 | 61 | }, |
| 35 | 62 | { |
| 36 | 63 | title: '联系人', |
| ... | ... | @@ -60,6 +87,11 @@ const crudSchemas = reactive<VxeCrudSchema>({ |
| 60 | 87 | { |
| 61 | 88 | title: '账号额度', |
| 62 | 89 | field: 'accountCount', |
| 90 | + table: { | |
| 91 | + slots: { | |
| 92 | + default: 'accountCount_default' | |
| 93 | + } | |
| 94 | + }, | |
| 63 | 95 | form: { |
| 64 | 96 | component: 'InputNumber' |
| 65 | 97 | } | ... | ... |