list.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <template>
  2. <div class="p-4">
  3. <BasicTable @register="registerTable">
  4. <template #toolbar>
  5. <a-button
  6. type="primary"
  7. @click="handleCreate"
  8. v-if="getCheckPerm('lanuser-add')"
  9. >添加用户</a-button
  10. ><a-button
  11. type="primary"
  12. v-if="getCheckPerm('lanuser-all')"
  13. @click="openModalPut(true, {})"
  14. >批量导入</a-button
  15. >
  16. </template>
  17. <template #role="{ record }">
  18. {{ renderRoleType(record.role) }}
  19. </template>
  20. <template #status="{ record }">
  21. {{ renderStatus(record.status) }}
  22. </template>
  23. <template #createTime="{ record }">
  24. <Time :value="record.createTime" mode="datetime" />
  25. </template>
  26. <!-- , -->
  27. <template #action="{ record }">
  28. <TableAction
  29. :actions="[
  30. {
  31. // color: 'warning',
  32. // label: '重置密码',
  33. // ifShow:getCheckPerm('lanuser-pasword'),
  34. // onClick: handleOpenModal.bind(null, record),
  35. //},{
  36. label: '编辑',
  37. ifShow: getCheckPerm('lanuser-update'),
  38. onClick: handleEdit.bind(null, record),
  39. },
  40. {
  41. label: '删除',
  42. color: 'error',
  43. ifShow: getCheckPerm('lanuser-delete'),
  44. onClick:handDelconfirm.bind(null, record),
  45. },
  46. ]"
  47. />
  48. </template>
  49. </BasicTable>
  50. <DetailsModal @register="registerDetail" @ok="reload" />
  51. <SetpaswordModal @register="register" @reload="reload" />
  52. <addDetailsModal @register="registerAddDetail" @ok="reload" />
  53. <batchPutModal @register="registerPut" @reload="reload" />
  54. </div>
  55. </template>
  56. <script lang="ts">
  57. import { defineComponent, computed, onMounted, ref, h } from 'vue';
  58. import { BasicTable, useTable, BasicColumn, FormProps, TableAction } from '/@/components/Table';
  59. import { useMessage } from '/@/hooks/web/useMessage';
  60. import { useModal } from '/@/components/Modal';
  61. import { uploadApi } from '/@/api/sys/upload';
  62. import SetpaswordModal from './setpaswordModal.vue';
  63. import DetailsModal from './detailsModal.vue';
  64. import batchPutModal from './batchPutModal.vue';
  65. import addDetailsModal from './adddetailsModal.vue';
  66. import { Switch } from 'ant-design-vue';
  67. // import DelListModal from './delListModal.vue';
  68. import { Alert } from 'ant-design-vue';
  69. // import { h } from 'vue';
  70. import { delUcenterUser, preDelApi, updateApi, getNumByStaff } from '/@/api/staff/list';
  71. import { ListApi } from '/@/api/account';
  72. import { useI18n } from '/@/hooks/web/useI18n';
  73. // import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
  74. import { RoleEnum } from '/@/enums/roleEnum';
  75. import { useGo } from '/@/hooks/web/usePage';
  76. import { Time } from '/@/components/Time';
  77. import { useUserStore } from '/@/store/modules/user';
  78. import { usePermissionStore } from '/@/store/modules/permission';
  79. import { yhList } from '/@/api/jyUserPlatform/index'; //roleLIstApi
  80. export default defineComponent({
  81. components: {
  82. BasicTable,
  83. TableAction,
  84. Time,
  85. SetpaswordModal,
  86. batchPutModal,
  87. DetailsModal,
  88. addDetailsModal,
  89. Alert,
  90. },
  91. setup() {
  92. const [register, { openModal }] = useModal();
  93. const surplusSubNum = ref({
  94. lookNum: 0,
  95. shotNum: 0,
  96. });
  97. const [registerDetail, { openModal: openDetaileModal }] = useModal();
  98. const [registerAddDetail, { openModal: openAddDetaileModal }] = useModal();
  99. const [registerDelList, { openModal: openDelListeModal }] = useModal();
  100. const [registerPut, { openModal:openModalPut }] = useModal();
  101. const { createConfirm, createMessage } = useMessage();
  102. const userStore = useUserStore();
  103. const permissionStore = usePermissionStore();
  104. const { getCheckPerm } = permissionStore;
  105. const roleList = computed(() => userStore.getRoleList);
  106. console.log('getRoleList', roleList);
  107. const go = useGo();
  108. const { t } = useI18n();
  109. onMounted(() => {
  110. // getNumByStaffData();
  111. });
  112. const columns: BasicColumn[] = [
  113. {
  114. title: t('routes.staff.userName'),
  115. dataIndex: 'name',
  116. ellipsis: true,
  117. width: 120,
  118. },
  119. {
  120. title: '人员编号',
  121. dataIndex: 'ryNo',
  122. ellipsis: true,
  123. width: 150,
  124. },
  125. {
  126. title: '人员ID',
  127. dataIndex: 'ryId',
  128. ellipsis: true,
  129. width: 100,
  130. },
  131. {
  132. title: '手机号码',
  133. ellipsis: true,
  134. dataIndex: 'phone',
  135. width: 100,
  136. },
  137. {
  138. title: '身份证',
  139. ellipsis: true,
  140. dataIndex: 'idCard',
  141. width: 160,
  142. customRender: ({ record }) => {
  143. return IdNumber(record.idCard);
  144. }
  145. },
  146. {
  147. title: '平台',
  148. ellipsis: true,
  149. dataIndex: 'platformName',
  150. width: 80,
  151. },
  152. {
  153. title: '注册时间',
  154. dataIndex: 'createTime',
  155. ellipsis: true,
  156. slots: { customRender: 'createTime' },
  157. width: 130,
  158. },
  159. {
  160. title: '状态',
  161. dataIndex: 'status',
  162. // ifShow:getCheckPerm('sysuser-enable'),
  163. width: 80,
  164. customRender: ({ record }) => {
  165. return record.status == 1 ? '启用' : '禁用';
  166. if (!Reflect.has(record, 'status')) {
  167. record.pendingStatus = false;
  168. }
  169. return h(Switch, {
  170. checked: record.status == 1 ? true : false,
  171. checkedChildren: '启用',
  172. unCheckedChildren: '禁用',
  173. loading: false,
  174. onChange: async (checked: boolean) => {
  175. record.pendingStatus = true;
  176. const newStatus = checked?1:0;
  177. await updateApi({...record,status:newStatus});
  178. Reflect.set(record, 'status', checked);
  179. createMessage.success(t('common.optSuccess'));
  180. reload()
  181. },
  182. });
  183. },
  184. },
  185. // {
  186. // title: '操作',
  187. // dataIndex: '',
  188. // // ifShow: !getCheckRole('tourist'),
  189. // slots: { customRender: 'action' },
  190. // fixed: 'right',
  191. // flag: 'ACTION',
  192. // width: 100,
  193. // },
  194. ];
  195. const searchForm: Partial<FormProps> = {
  196. labelWidth: 80,
  197. schemas: [
  198. {
  199. field: 'name',
  200. label: t('routes.staff.userName'),
  201. component: 'Input',
  202. componentProps: {
  203. maxLength: 15,
  204. },
  205. colProps: {
  206. xl: 6,
  207. xxl: 6,
  208. },
  209. },
  210. {
  211. field: 'ryNo',
  212. label: '人员编号',
  213. component: 'Input',
  214. componentProps: {
  215. maxLength: 15,
  216. },
  217. colProps: {
  218. xl: 6,
  219. xxl: 6,
  220. },
  221. },
  222. {
  223. field: 'idCard',
  224. label: '身份证',
  225. component: 'Input',
  226. componentProps: {
  227. maxLength: 15,
  228. },
  229. colProps: {
  230. xl: 6,
  231. xxl: 6,
  232. },
  233. },
  234. {
  235. field: 'phone',
  236. label: '手机号码',
  237. component: 'Input',
  238. componentProps: {
  239. maxLength: 15,
  240. },
  241. colProps: {
  242. xl: 6,
  243. xxl: 6,
  244. },
  245. },
  246. ],
  247. };
  248. const [registerTable, { reload }] = useTable({
  249. title: '用户列表',
  250. api: yhList,
  251. columns: columns,
  252. useSearchForm: true,
  253. formConfig: searchForm,
  254. showTableSetting: true,
  255. tableSetting: { fullScreen: true },
  256. showIndexColumn: false,
  257. canResize: true,
  258. rowKey: 'id',
  259. fetchSetting: {
  260. pageField: 'pageNum',
  261. sizeField: 'pageSize',
  262. listField: 'list',
  263. totalField: 'total',
  264. },
  265. pagination: { pageSize: 10 },
  266. afterFetch: (T) => {
  267. return T;
  268. },
  269. bordered: true,
  270. sortFn: (sortInfo) => {
  271. let order = sortInfo.order && sortInfo.order.replace('end', '');
  272. return { ...sortInfo, sidx: sortInfo.field, order: order };
  273. },
  274. });
  275. function renderRoleType(type: number): string {
  276. switch (type) {
  277. case 0:
  278. return t('routes.staff.roleType.0');
  279. case 1:
  280. return t('routes.staff.roleType.1');
  281. default:
  282. return '';
  283. }
  284. }
  285. function renderStatus(type: number): string {
  286. switch (type) {
  287. case 1:
  288. return t('common.normal');
  289. case 0:
  290. return t('common.unNormal');
  291. default:
  292. return '';
  293. }
  294. }
  295. function handleOpenModal(record: Recordable) {
  296. openModal(true, record);
  297. }
  298. function handleCreate() {
  299. openAddDetaileModal(true,{});
  300. }
  301. function handleEdit(record: Recordable) {
  302. openDetaileModal(true, {
  303. ...record,
  304. phone:record.userName,
  305. });
  306. }
  307. function getNumByStaffData() {
  308. getNumByStaff({}).then((res) => {
  309. surplusSubNum.value.lookNum = res.lookNum;
  310. surplusSubNum.value.shotNum = res.shotNum;
  311. });
  312. }
  313. async function handleDelete(record) {
  314. let check = await preDelApi(record.id); //
  315. if (Array.isArray(check)) {
  316. return openDelListeModal(true, {
  317. ...record,
  318. option: check,
  319. });
  320. }
  321. createMessage.success(t('common.optSuccess'));
  322. reload();
  323. // handDelconfirm(record);
  324. }
  325. function handDelconfirm(record) {
  326. createConfirm({
  327. iconType: 'warning',
  328. title: '警告',
  329. content: `此操作将对${record.userName}进行删除, 是否继续?`,
  330. onOk: async () => {
  331. await delUcenterUser({ id: record.id });
  332. createMessage.success(t('common.optSuccess'));
  333. reload();
  334. },
  335. });
  336. }
  337. function IdNumber(num){
  338. if (!num) return "";
  339. return num.replace(/(?<=\d{3})\d{12}(?=\d{2})/,"************")
  340. }
  341. return {
  342. registerTable,
  343. registerDetail,
  344. registerDelList,
  345. registerAddDetail,
  346. openDelListeModal,
  347. createMessage,
  348. handDelconfirm,
  349. t,
  350. reload,
  351. go,
  352. renderRoleType,
  353. renderStatus,
  354. handleCreate,
  355. handleOpenModal,
  356. register,
  357. handleEdit,
  358. handleDelete,
  359. uploadApi: uploadApi as any,
  360. RoleEnum,
  361. surplusSubNum,
  362. getCheckPerm,
  363. getNumByStaffData,
  364. openModalPut,
  365. registerPut,
  366. };
  367. },
  368. });
  369. </script>