index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <script lang="ts" setup>
  2. import type { VbenFormProps } from '@vben/common-ui';
  3. import type { VxeGridListeners, VxeGridProps } from '#/adapter/vxe-table';
  4. import { h } from 'vue';
  5. import { Page, useVbenModal } from '@vben/common-ui';
  6. import { MdiDelete, MdiDetail, MdiEdit } from '@vben/icons';
  7. import { ElMessage, ElMessageBox, ElTag } from 'element-plus';
  8. import { useVbenVxeGrid } from '#/adapter/vxe-table';
  9. import { deleteDictApi, getDictListApi } from '#/api/dict';
  10. import { $t } from '#/locales';
  11. import DictForm from './form.vue';
  12. const formOptions: VbenFormProps = {
  13. // 默认展开
  14. collapsed: true,
  15. // 控制表单是否显示折叠按钮
  16. showCollapseButton: true,
  17. // 按下回车时是否提交表单
  18. submitOnEnter: true,
  19. schema: [
  20. {
  21. component: 'Input',
  22. fieldName: 'title',
  23. label: '配置名称',
  24. componentProps: {
  25. placeholder: $t('ui.placeholder.input'),
  26. clearable: true,
  27. },
  28. },
  29. {
  30. component: 'Input',
  31. fieldName: 'groupname',
  32. label: '组名称',
  33. componentProps: {
  34. placeholder: $t('ui.placeholder.input'),
  35. clearable: true,
  36. },
  37. },
  38. {
  39. component: 'Select',
  40. fieldName: 'available',
  41. label: '状态',
  42. componentProps: {
  43. placeholder: $t('ui.placeholder.select'),
  44. clearable: true,
  45. options: [
  46. { label: '可用', value: 1 },
  47. { label: '不可用', value: 0 },
  48. ],
  49. },
  50. },
  51. ],
  52. wrapperClass: 'grid-cols-1 md:grid-cols-3 lg:grid-cols-5',
  53. };
  54. const gridOptions: VxeGridProps<any> = {
  55. toolbarConfig: {
  56. custom: true,
  57. export: true,
  58. refresh: true,
  59. zoom: true,
  60. },
  61. height: 'auto',
  62. exportConfig: {},
  63. pagerConfig: {},
  64. rowConfig: {
  65. isHover: true,
  66. },
  67. stripe: true,
  68. proxyConfig: {
  69. response: {
  70. result: 'Data',
  71. total: 'Total',
  72. },
  73. ajax: {
  74. query: async ({ page }, formValues) => {
  75. return await getDictListApi({
  76. pageindex: page.currentPage,
  77. rows: page.pageSize,
  78. ...formValues,
  79. });
  80. },
  81. },
  82. },
  83. columns: [
  84. { title: 'ID', field: 'id', sortable: true },
  85. { title: '配置名称', field: 'title', sortable: true },
  86. { title: '组名称', field: 'groupname', sortable: true },
  87. { title: '配置值', field: 'substance', sortable: true },
  88. {
  89. title: '状态',
  90. field: 'available',
  91. sortable: true,
  92. slots: {
  93. default: ({ row }) => {
  94. const status = row.available;
  95. return h(
  96. ElTag,
  97. {
  98. type: status === 1 ? 'success' : 'danger',
  99. effect: 'dark',
  100. size: 'small',
  101. round: true,
  102. },
  103. () => (status === 1 ? '可用' : '不可用'),
  104. );
  105. },
  106. },
  107. },
  108. { title: '描述', field: 'describes', sortable: true },
  109. {
  110. title: '前端可用',
  111. field: 'ispublic',
  112. slots: {
  113. default: ({ row }) => {
  114. const status = row.ispublic;
  115. return h(
  116. ElTag,
  117. {
  118. type: status === 1 ? 'success' : 'info',
  119. effect: 'light',
  120. size: 'small',
  121. },
  122. () => (status === 1 ? '是' : '否'),
  123. );
  124. },
  125. },
  126. },
  127. // { title: '排序值', field: 'ranknum' },
  128. {
  129. title: '操作',
  130. field: 'action',
  131. fixed: 'right',
  132. slots: { default: 'action' },
  133. width: 150,
  134. },
  135. ],
  136. };
  137. const gridEvents: VxeGridListeners<any> = {
  138. cellDblclick: ({ row }) => {
  139. handleDetail(row);
  140. },
  141. };
  142. const [Grid, gridApi] = useVbenVxeGrid({
  143. gridEvents,
  144. gridOptions,
  145. formOptions,
  146. });
  147. const [Modal, modalApi] = useVbenModal({
  148. fullscreenButton: false,
  149. closeOnClickModal: false,
  150. closeOnPressEscape: false,
  151. connectedComponent: DictForm,
  152. });
  153. /* 创建 */
  154. function handleCreate() {
  155. modalApi.setState({ showCancelButton: true });
  156. modalApi.setData({ formType: 'create' }).open();
  157. }
  158. /* 编辑 */
  159. function handleEdit(row: any) {
  160. modalApi.setState({ showCancelButton: true });
  161. modalApi.setData({ formType: 'edit', row }).open();
  162. }
  163. /* 详情 */
  164. function handleDetail(row: any) {
  165. modalApi.setState({ showCancelButton: false });
  166. modalApi.setData({ formType: 'detail', row }).open();
  167. }
  168. /* 删除 */
  169. async function handleDelete(row: any) {
  170. try {
  171. await ElMessageBox.confirm('确认要删除该配置吗?', '提示', {
  172. confirmButtonText: '确定',
  173. cancelButtonText: '取消',
  174. type: 'warning',
  175. });
  176. await deleteDictApi({ 'id.value': row.id });
  177. ElMessage.success('删除成功');
  178. gridApi.reload();
  179. } catch (error) {
  180. console.error(error);
  181. }
  182. }
  183. function handleFinish() {
  184. gridApi.reload();
  185. }
  186. </script>
  187. <template>
  188. <Page auto-content-height>
  189. <Grid table-title="数据字典列表">
  190. <template #toolbar-tools>
  191. <el-button type="primary" @click="handleCreate"> 新增 </el-button>
  192. </template>
  193. <template #action="{ row }">
  194. <el-tooltip
  195. class="box-item"
  196. effect="dark"
  197. content="详情"
  198. placement="top"
  199. >
  200. <el-button
  201. round
  202. @click="() => handleDetail(row)"
  203. :icon="MdiDetail"
  204. class="!p-2"
  205. />
  206. </el-tooltip>
  207. <el-tooltip
  208. class="box-item"
  209. effect="dark"
  210. content="编辑"
  211. placement="top"
  212. >
  213. <el-button
  214. round
  215. @click="() => handleEdit(row)"
  216. :icon="MdiEdit"
  217. class="!p-2"
  218. />
  219. </el-tooltip>
  220. <el-tooltip
  221. class="box-item"
  222. effect="dark"
  223. content="删除"
  224. placement="top"
  225. >
  226. <el-button
  227. round
  228. @click="() => handleDelete(row)"
  229. :icon="MdiDelete"
  230. class="!p-2"
  231. />
  232. </el-tooltip>
  233. </template>
  234. </Grid>
  235. <Modal @finish="handleFinish" />
  236. </Page>
  237. </template>