apilist.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <div>
  3. <BasicTable @register="registerTable">
  4. <template #toolbar>
  5. <a-button type="primary" @click="handleEdit" v-if="getCheckPerm('empowerApi-add')"
  6. >新增</a-button
  7. >
  8. </template>
  9. <template #copy="{ text }">
  10. <a @click="handleCopy(text)">
  11. {{ text }}
  12. </a>
  13. </template>
  14. <template #action="{ record }">
  15. <TableAction
  16. :actions="[
  17. {
  18. label: '删除',
  19. color: 'error',
  20. ifShow: getCheckPerm('empowerApi-delete'),
  21. onClick: handleDelete.bind(null, record),
  22. },
  23. ]"
  24. />
  25. </template>
  26. </BasicTable>
  27. <AddModal @register="register" @update="reload" />
  28. </div>
  29. </template>
  30. <script lang="ts">
  31. import { defineComponent, h } from 'vue';
  32. import { BasicTable, useTable, TableAction, BasicColumn, FormProps } from '/@/components/Table';
  33. import { authorizeOpenApilist, authorizeOpenApidelete, authorizeOpenApiupdate } from '/@/api/authorizeModeling';
  34. import { useModal } from '/@/components/Modal';
  35. import { useI18n } from '/@/hooks/web/useI18n';
  36. import AddModal from './modal/api/AddApiModal.vue';
  37. import { useMessage } from '/@/hooks/web/useMessage';
  38. import { usePermissionStore } from '/@/store/modules/permission';
  39. import { copyTextToClipboard } from '/@/hooks/web/useCopyToClipboard';
  40. import { incrementUseTypeList } from '/@/api/account';
  41. import { Switch } from 'ant-design-vue';
  42. export default defineComponent({
  43. components: {
  44. BasicTable,
  45. AddModal,
  46. TableAction,
  47. },
  48. setup() {
  49. const { t } = useI18n();
  50. const { createMessage, createConfirm } = useMessage();
  51. const permissionStore = usePermissionStore();
  52. const { getCheckPerm } = permissionStore;
  53. const [register, { openModal }] = useModal();
  54. const columns: BasicColumn[] = [
  55. {
  56. title: 'API KEY',
  57. ellipsis: true,
  58. slots: { customRender: 'copy' },
  59. dataIndex: 'apiKey',
  60. width: 200,
  61. },
  62. {
  63. title: '生效时间',
  64. ellipsis: true,
  65. dataIndex: 'effectTime',
  66. width: 120,
  67. },
  68. {
  69. title: '四维看看账号',
  70. ellipsis: true,
  71. dataIndex: 'userName',
  72. width: 120,
  73. },
  74. {
  75. title: '合同所属公司',
  76. dataIndex: 'companyName',
  77. ellipsis: true,
  78. width: 230,
  79. },
  80. {
  81. title: '业务部门',
  82. dataIndex: 'businessDept',
  83. ellipsis: true,
  84. width: 120,
  85. },
  86. {
  87. title: '业务员',
  88. dataIndex: 'businessName',
  89. ellipsis: true,
  90. width: 120,
  91. },
  92. {
  93. title: '客户名称',
  94. dataIndex: 'customerName',
  95. ellipsis: true,
  96. width: 100,
  97. },
  98. {
  99. title: '客户类别',
  100. dataIndex: 'customerType',
  101. ellipsis: true,
  102. width: 80,
  103. customRender: ({ record }) => {
  104. return record.customerType == 1 ? '经销' : record.customerType == 0 ? '直销' : '';
  105. },
  106. },
  107. {
  108. title: '终端客户',
  109. ellipsis: true,
  110. dataIndex: 'endCustomer',
  111. width: 120,
  112. },
  113. {
  114. title: '使用类型',
  115. ellipsis: true,
  116. dataIndex: 'useTypeStr',
  117. width: 120,
  118. },
  119. {
  120. title: '备注',
  121. ellipsis: true,
  122. dataIndex: 'remark',
  123. width: 120,
  124. },
  125. {
  126. title: '操作人',
  127. ellipsis: true,
  128. dataIndex: 'updaterName',
  129. width: 120,
  130. },
  131. {
  132. title: '操作时间',
  133. ellipsis: true,
  134. dataIndex: 'updateTime',
  135. width: 160,
  136. },
  137. {
  138. title: '状态',
  139. dataIndex: 'status',
  140. width: 80,
  141. customRender: ({ record }) => {
  142. if (!Reflect.has(record, 'pendingStatus')) {
  143. record.pendingStatus = false;
  144. }
  145. return h(Switch, {
  146. checked: record.status == '1',
  147. checkedChildren: '启用',
  148. unCheckedChildren: '禁用',
  149. loading: false,
  150. onChange: async (checked: boolean) => {
  151. record.pendingStatus = true;
  152. const newStatus = checked ? '1' : '0';
  153. await authorizeOpenApiupdate({ ...record, status: newStatus });
  154. if (checked) {
  155. Reflect.set(record, 'status', newStatus);
  156. } else {
  157. Reflect.set(record, 'status', newStatus);
  158. }
  159. // reload();
  160. createMessage.success(t('common.optSuccess'));
  161. },
  162. });
  163. },
  164. },
  165. ];
  166. const searchForm: Partial<FormProps> = {
  167. labelWidth: 100,
  168. autoSubmitOnEnter: true,
  169. schemas: [
  170. {
  171. field: 'apiKey',
  172. label: 'API KEY',
  173. component: 'Input',
  174. colProps: {
  175. xl: 8,
  176. xxl: 8,
  177. },
  178. },
  179. {
  180. field: 'userName',
  181. label: '四维看看账号',
  182. component: 'Input',
  183. colProps: {
  184. xl: 8,
  185. xxl: 8,
  186. },
  187. },
  188. ],
  189. };
  190. const [registerTable, { reload }] = useTable({
  191. api: authorizeOpenApilist,
  192. title: 'API授权列表',
  193. columns: columns,
  194. useSearchForm: true,
  195. formConfig: searchForm,
  196. showTableSetting: true,
  197. showIndexColumn: false,
  198. fetchSetting: {
  199. pageField: 'pageNum',
  200. sizeField: 'pageSize',
  201. listField: 'list',
  202. totalField: 'total',
  203. },
  204. actionColumn: {
  205. width: 150,
  206. title: '操作',
  207. dataIndex: 'action',
  208. slots: { customRender: 'action' },
  209. },
  210. rowKey: 'id',
  211. canResize: true,
  212. });
  213. async function handleDelete(record) {
  214. createConfirm({
  215. iconType: 'warning',
  216. title: () => h('span', '温馨提示'),
  217. content: () => h('span', '确定要删除授权吗?'),
  218. onOk: async () => {
  219. await authorizeOpenApidelete({ id: record.id });
  220. reload();
  221. createMessage.success(t('common.optSuccess'));
  222. },
  223. });
  224. }
  225. function handleEdit(record = {}) {
  226. openModal(true, record);
  227. }
  228. function handleDetail(record = {}) {
  229. opendetailModel(true, record);
  230. }
  231. function handleCopy(str: string) {
  232. copyTextToClipboard(str);
  233. createMessage.success('复制成功');
  234. }
  235. return {
  236. registerTable,
  237. handleCopy,
  238. handleDelete,
  239. reload,
  240. register,
  241. getCheckPerm,
  242. handleEdit,
  243. handleDetail,
  244. };
  245. },
  246. });
  247. </script>