index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <ContentWrap>
  3. <!-- 列表 -->
  4. <XTable @register="registerTable">
  5. <template #toolbar_buttons>
  6. <!-- 操作:新增 -->
  7. <XButton
  8. type="primary"
  9. preIcon="ep:zoom-in"
  10. :title="t('action.add')"
  11. v-hasPermi="['system:tenant:create']"
  12. @click="handleCreate()"
  13. />
  14. <XButton
  15. type="warning"
  16. preIcon="ep:download"
  17. :title="t('action.export')"
  18. v-hasPermi="['system:tenant:export']"
  19. @click="handleExport()"
  20. />
  21. </template>
  22. <template #accountCount_default="{ row }">
  23. <el-tag> {{ row.accountCount }} </el-tag>
  24. </template>
  25. <template #packageId_default="{ row }">
  26. <el-tag v-if="row.packageId === 0" type="danger">系统租户</el-tag>
  27. <el-tag v-else type="success"> {{ getPackageName(row.packageId) }} </el-tag>
  28. </template>
  29. <template #actionbtns_default="{ row }">
  30. <!-- 操作:修改 -->
  31. <XTextButton
  32. preIcon="ep:edit"
  33. :title="t('action.edit')"
  34. v-hasPermi="['system:tenant:update']"
  35. @click="handleUpdate(row.id)"
  36. />
  37. <!-- 操作:详情 -->
  38. <XTextButton
  39. preIcon="ep:view"
  40. :title="t('action.detail')"
  41. v-hasPermi="['system:tenant:update']"
  42. @click="handleDetail(row.id)"
  43. />
  44. <!-- 操作:删除 -->
  45. <XTextButton
  46. preIcon="ep:delete"
  47. :title="t('action.del')"
  48. v-hasPermi="['system:tenant:delete']"
  49. @click="handleDelete(row.id)"
  50. />
  51. </template>
  52. </XTable>
  53. </ContentWrap>
  54. <XModal v-model="dialogVisible" :title="dialogTitle">
  55. <!-- 对话框(添加 / 修改) -->
  56. <Form
  57. v-if="['create', 'update'].includes(actionType)"
  58. :schema="allSchemas.formSchema"
  59. :rules="rules"
  60. ref="formRef"
  61. />
  62. <!-- 对话框(详情) -->
  63. <Descriptions
  64. v-if="actionType === 'detail'"
  65. :schema="allSchemas.detailSchema"
  66. :data="detailData"
  67. >
  68. <template #packageId="{ row }">
  69. <el-tag v-if="row.packageId === 0" type="danger">系统租户</el-tag>
  70. <el-tag v-else type="success"> {{ getPackageName(row.packageId) }} </el-tag>
  71. </template>
  72. </Descriptions>
  73. <!-- 操作按钮 -->
  74. <template #footer>
  75. <!-- 按钮:保存 -->
  76. <XButton
  77. v-if="['create', 'update'].includes(actionType)"
  78. type="primary"
  79. :title="t('action.save')"
  80. :loading="actionLoading"
  81. @click="submitForm()"
  82. />
  83. <!-- 按钮:关闭 -->
  84. <XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
  85. </template>
  86. </XModal>
  87. </template>
  88. <script setup lang="ts" name="Tenant">
  89. import { ref, unref } from 'vue'
  90. import { useI18n } from '@/hooks/web/useI18n'
  91. import { useMessage } from '@/hooks/web/useMessage'
  92. import { useXTable } from '@/hooks/web/useXTable'
  93. import { ElTag } from 'element-plus'
  94. import { FormExpose } from '@/components/Form'
  95. import * as TenantApi from '@/api/system/tenant'
  96. import { rules, allSchemas, tenantPackageOption } from './tenant.data'
  97. const { t } = useI18n() // 国际化
  98. const message = useMessage() // 消息弹窗
  99. // 列表相关的变量
  100. const [registerTable, { reload, deleteData, exportList }] = useXTable({
  101. allSchemas: allSchemas,
  102. getListApi: TenantApi.getTenantPageApi,
  103. deleteApi: TenantApi.deleteTenantApi,
  104. exportListApi: TenantApi.exportTenantApi
  105. })
  106. const actionLoading = ref(false) // 遮罩层
  107. const actionType = ref('') // 操作按钮的类型
  108. const dialogVisible = ref(false) // 是否显示弹出层
  109. const dialogTitle = ref('edit') // 弹出层标题
  110. const formRef = ref<FormExpose>() // 表单 Ref
  111. const detailData = ref() // 详情 Ref
  112. const getPackageName = (packageId: number) => {
  113. for (let item of tenantPackageOption) {
  114. if (item.value === packageId) {
  115. return item.label
  116. }
  117. }
  118. return '未知套餐'
  119. }
  120. // 设置标题
  121. const setDialogTile = (type: string) => {
  122. dialogTitle.value = t('action.' + type)
  123. actionType.value = type
  124. dialogVisible.value = true
  125. }
  126. // 新增操作
  127. const handleCreate = () => {
  128. // 重置表单
  129. setDialogTile('create')
  130. }
  131. // 修改操作
  132. const handleUpdate = async (rowId: number) => {
  133. setDialogTile('update')
  134. // 设置数据
  135. const res = await TenantApi.getTenantApi(rowId)
  136. unref(formRef)?.setValues(res)
  137. }
  138. // 详情操作
  139. const handleDetail = async (rowId: number) => {
  140. // 设置数据
  141. const res = await TenantApi.getTenantApi(rowId)
  142. detailData.value = res
  143. setDialogTile('detail')
  144. }
  145. // 删除操作
  146. const handleDelete = async (rowId: number) => {
  147. await deleteData(rowId)
  148. }
  149. // 导出操作
  150. const handleExport = async () => {
  151. await exportList('租户列表.xls')
  152. }
  153. // 提交按钮
  154. const submitForm = async () => {
  155. const elForm = unref(formRef)?.getElFormRef()
  156. if (!elForm) return
  157. elForm.validate(async (valid) => {
  158. if (valid) {
  159. actionLoading.value = true
  160. // 提交请求
  161. try {
  162. const data = unref(formRef)?.formModel as TenantApi.TenantVO
  163. if (actionType.value === 'create') {
  164. await TenantApi.createTenantApi(data)
  165. message.success(t('common.createSuccess'))
  166. } else {
  167. await TenantApi.updateTenantApi(data)
  168. message.success(t('common.updateSuccess'))
  169. }
  170. // 操作成功,重新加载列表
  171. dialogVisible.value = false
  172. } finally {
  173. actionLoading.value = false
  174. // 刷新列表
  175. await reload()
  176. }
  177. }
  178. })
  179. }
  180. </script>