algorithm.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <div>
  3. <BasicTable @register="registerTable">
  4. <template #toolbar>
  5. <a-button type="primary" @click="handleEdit" v-if="getCheckPerm('algorithm-add')"
  6. >授权</a-button
  7. >
  8. </template>
  9. <template #copy="{ record }">
  10. <a @click="handleCopy(record.authorizeKey)">
  11. {{ record.authorizeKey }}
  12. </a>
  13. </template>
  14. <template #action="{ record }">
  15. <TableAction
  16. :actions="[
  17. {
  18. label: '编辑',
  19. ifShow: getCheckPerm('algorithm-updata'),
  20. onClick: handleEdit.bind(null, record),
  21. },
  22. {
  23. label: '删除',
  24. color: 'error',
  25. ifShow: getCheckPerm('algorithm-delete'),
  26. onClick: handleDelete.bind(null, record),
  27. },
  28. ]"
  29. />
  30. </template>
  31. </BasicTable>
  32. <AddModal @register="register" @update="reload" />
  33. </div>
  34. </template>
  35. <script lang="ts">
  36. import { defineComponent, h } from 'vue';
  37. import {
  38. BasicTable,
  39. useTable,
  40. TableAction,
  41. BasicColumn,
  42. TableImg,
  43. FormProps,
  44. } from '/@/components/Table';
  45. import {
  46. authorizeModelingList,
  47. authorizeModelingaddOrUpdate,
  48. authorizeModelingdelete,
  49. } from '/@/api/authorizeModeling';
  50. import { useModal } from '/@/components/Modal';
  51. import { useI18n } from '/@/hooks/web/useI18n';
  52. import AddModal from './AddModal.vue';
  53. import { useMessage } from '/@/hooks/web/useMessage';
  54. import { usePermissionStore } from '/@/store/modules/permission';
  55. import { incrementUseTypeList } from '/@/api/account';
  56. export default defineComponent({
  57. components: {
  58. BasicTable,
  59. AddModal,
  60. TableAction,
  61. TableImg,
  62. },
  63. setup() {
  64. const { t } = useI18n();
  65. const { createMessage, createConfirm } = useMessage();
  66. const permissionStore = usePermissionStore();
  67. const { getCheckPerm } = permissionStore;
  68. const [register, { openModal }] = useModal();
  69. const columns: BasicColumn[] = [
  70. {
  71. title: '客户名称',
  72. dataIndex: 'customerName',
  73. ellipsis: true,
  74. width: 250,
  75. },
  76. {
  77. title: '客户类别',
  78. dataIndex: 'customerType',
  79. ellipsis: true,
  80. width: 80,
  81. customRender: ({ record }) => {
  82. return record.customerType == 1 ? '经销' : '直销';
  83. },
  84. },
  85. {
  86. title: '终端客户',
  87. ellipsis: true,
  88. dataIndex: 'endCustomer',
  89. width: 120,
  90. },
  91. {
  92. title: '使用类型',
  93. ellipsis: true,
  94. dataIndex: 'useTypeStr',
  95. width: 120,
  96. },
  97. {
  98. title: '项目号',
  99. ellipsis: true,
  100. dataIndex: 'projectNum',
  101. width: 120,
  102. },
  103. {
  104. title: '算法授权Key',
  105. ellipsis: true,
  106. slots: { customRender: 'copy' },
  107. dataIndex: 'authorizeKey',
  108. width: 120,
  109. },
  110. {
  111. title: '授权期限',
  112. ellipsis: true,
  113. dataIndex: 'authorizeTime',
  114. width: 120,
  115. customRender: ({ record }) => {
  116. let obj = {
  117. 1: '天',
  118. 2: '个月',
  119. 3: '年',
  120. };
  121. return record.authorizeTime + obj[record.authorizeTimeUnit];
  122. },
  123. },
  124. {
  125. title: '授权说明',
  126. ellipsis: true,
  127. dataIndex: 'remark',
  128. width: 120,
  129. },
  130. {
  131. title: '创建人',
  132. ellipsis: true,
  133. dataIndex: 'sysUserName',
  134. width: 120,
  135. },
  136. {
  137. title: '创建时间',
  138. ellipsis: true,
  139. dataIndex: 'createTime',
  140. width: 160,
  141. },
  142. ];
  143. const searchForm: Partial<FormProps> = {
  144. labelWidth: 100,
  145. autoSubmitOnEnter: true,
  146. schemas: [
  147. {
  148. field: 'customerName',
  149. label: '客户名称',
  150. component: 'Input',
  151. colProps: {
  152. xl: 8,
  153. xxl: 8,
  154. },
  155. },
  156. {
  157. field: 'customerType',
  158. label: '客户类别',
  159. component: 'Select',
  160. componentProps: {
  161. options: [
  162. {
  163. label: '直销',
  164. value: 0,
  165. key: '0',
  166. },
  167. {
  168. label: '经销',
  169. value: 1,
  170. key: '1',
  171. },
  172. ],
  173. },
  174. colProps: {
  175. xl: 8,
  176. xxl: 8,
  177. },
  178. },
  179. {
  180. field: 'useType',
  181. label: '使用类型',
  182. component: 'ApiSelect',
  183. componentProps: {
  184. api: incrementUseTypeList,
  185. labelField: 'name',
  186. valueField: 'id',
  187. immediate: true,
  188. },
  189. colProps: {
  190. xl: 8,
  191. xxl: 8,
  192. },
  193. },
  194. {
  195. field: 'authorizeKey',
  196. label: '算法授权Key',
  197. component: 'Input',
  198. colProps: {
  199. xl: 8,
  200. xxl: 8,
  201. },
  202. },
  203. ],
  204. };
  205. const [registerTable, { reload }] = useTable({
  206. api: authorizeModelingList,
  207. title: '算法授权列表',
  208. columns: columns,
  209. useSearchForm: true,
  210. formConfig: searchForm,
  211. showTableSetting: true,
  212. showIndexColumn: false,
  213. fetchSetting: {
  214. pageField: 'pageNum',
  215. sizeField: 'pageSize',
  216. listField: 'list',
  217. totalField: 'total',
  218. },
  219. actionColumn: {
  220. width: 100,
  221. title: '操作',
  222. dataIndex: 'action',
  223. slots: { customRender: 'action' },
  224. },
  225. rowKey: 'id',
  226. canResize: true,
  227. });
  228. async function handleDelete(record) {
  229. createConfirm({
  230. iconType: 'warning',
  231. title: () => h('span', '温馨提示'),
  232. content: () => h('span', '确定要删除授权吗?'),
  233. onOk: async () => {
  234. await authorizeModelingdelete({ id: record.id });
  235. reload();
  236. createMessage.success(t('common.optSuccess'));
  237. },
  238. });
  239. }
  240. function handleCopy(str: string) {
  241. let save = function (e) {
  242. e.clipboardData.setData('text/plain', str);
  243. e.preventDefault(); //阻止默认行为
  244. };
  245. document.addEventListener('copy', save); //添加一个copy事件
  246. document.execCommand('copy'); //执行copy方法
  247. createMessage.success('复制成功');
  248. }
  249. function handleEdit(record = {}) {
  250. openModal(true, {
  251. ...record,
  252. authorizeTime: `${record.authorizeTime || '10'}_${record.authorizeTimeUnit || '1'}`,
  253. });
  254. }
  255. return {
  256. registerTable,
  257. handleCopy,
  258. handleDelete,
  259. reload,
  260. register,
  261. getCheckPerm,
  262. handleEdit,
  263. };
  264. },
  265. });
  266. </script>