list.vue 9.6 KB

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