list copy.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <div class="p-4">
  3. <BasicTable @register="registerTable">
  4. <template #toolbar> </template>
  5. <template #cover="{ record }">
  6. <TableImg :size="150" :simpleShow="true" :imgList="[record.cover]" />
  7. </template>
  8. <template #action>
  9. <TableAction
  10. :actions="[
  11. {
  12. icon: 'clarity:note-edit-line',
  13. label: '编辑',
  14. onClick: () => {
  15. createMessage.info(`暂未接入`);
  16. },
  17. },
  18. {
  19. icon: 'ant-design:delete-outlined',
  20. color: 'error',
  21. label: '删除',
  22. popConfirm: {
  23. title: '是否确认删除',
  24. confirm: () => {
  25. createMessage.info(`暂未接入`);
  26. },
  27. },
  28. },
  29. ]"
  30. />
  31. </template>
  32. </BasicTable>
  33. </div>
  34. </template>
  35. <script lang="ts">
  36. import { defineComponent } from 'vue';
  37. import {
  38. BasicTable,
  39. useTable,
  40. BasicColumn,
  41. FormProps,
  42. TableAction,
  43. TableImg,
  44. } from '/@/components/Table';
  45. import { useMessage } from '/@/hooks/web/useMessage';
  46. import { uploadApi } from '/@/api/sys/upload';
  47. import { Switch } from 'ant-design-vue';
  48. import { h } from 'vue';
  49. import { ListApi } from '/@/api/scene/list';
  50. import { useI18n } from '/@/hooks/web/useI18n';
  51. export default defineComponent({
  52. components: { BasicTable, TableAction, TableImg },
  53. setup() {
  54. const { createMessage } = useMessage();
  55. const { t } = useI18n();
  56. const columns: BasicColumn[] = [
  57. {
  58. title: 'ID',
  59. dataIndex: 'id',
  60. fixed: 'left',
  61. width: 100,
  62. },
  63. {
  64. title: '场景名称',
  65. dataIndex: 'name',
  66. width: 230,
  67. },
  68. {
  69. title: '封面',
  70. dataIndex: 'cover',
  71. slots: { customRender: 'cover' },
  72. width: 120,
  73. },
  74. {
  75. title: '场景链接',
  76. dataIndex: 'link',
  77. slots: { customRender: 'link' },
  78. width: 180,
  79. },
  80. {
  81. title: '是否显示',
  82. dataIndex: 'isShow',
  83. width: 180,
  84. customRender: ({ record }) => {
  85. if (!Reflect.has(record, 'pendingStatus')) {
  86. record.pendingStatus = false;
  87. }
  88. return h(Switch, {
  89. checked: record.isShow,
  90. checkedChildren: t('common.yes'),
  91. unCheckedChildren: t('common.no'),
  92. loading: false,
  93. onChange(checked: boolean) {
  94. record.pendingStatus = true;
  95. const newStatus = checked ? '1' : '0';
  96. const { createMessage } = useMessage();
  97. createMessage.info(`暂未接入` + newStatus);
  98. // setRoleStatus(record.id, newStatus)
  99. // .then(() => {
  100. // record.status = newStatus;
  101. // createMessage.success(`已成功修改角色状态`);
  102. // })
  103. // .catch(() => {
  104. // createMessage.error('修改角色状态失败');
  105. // })
  106. // .finally(() => {
  107. // record.pendingStatus = false;
  108. // });
  109. },
  110. });
  111. },
  112. },
  113. {
  114. title: '操作',
  115. dataIndex: '',
  116. slots: { customRender: 'action' },
  117. width: 120,
  118. },
  119. ];
  120. const searchForm: Partial<FormProps> = {
  121. labelWidth: 100,
  122. schemas: [
  123. {
  124. field: 'id',
  125. label: 'id',
  126. component: 'Input',
  127. colProps: {
  128. xl: 3,
  129. xxl: 3,
  130. },
  131. },
  132. {
  133. field: 'userName',
  134. label: '企业账号',
  135. component: 'Input',
  136. colProps: {
  137. xl: 12,
  138. xxl: 8,
  139. },
  140. },
  141. ],
  142. };
  143. // { getForm }
  144. const [registerTable] = useTable({
  145. title: '场景列表',
  146. api: ListApi,
  147. columns: columns,
  148. useSearchForm: false,
  149. formConfig: searchForm,
  150. showTableSetting: true,
  151. tableSetting: { fullScreen: true },
  152. showIndexColumn: false,
  153. rowKey: 'id',
  154. //TODO
  155. fetchSetting: {
  156. pageField: 'pageNum',
  157. sizeField: 'pageSize',
  158. listField: 'list',
  159. totalField: 'total',
  160. },
  161. pagination: { pageSize: 20 },
  162. });
  163. // pagination.value = { pageSize: 20 };
  164. return {
  165. registerTable,
  166. createMessage,
  167. t,
  168. uploadApi: uploadApi as any,
  169. };
  170. },
  171. });
  172. </script>