index copy.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <div>
  3. <PageWrapper dense contentFullHeight contentClass="flex">
  4. <OrganizationIdTree @select="handleSelect" ref="organizationIdTreeRef" />
  5. <BasicTable style="flex: auto" :clickToRowSelect="false" @register="registerTable" class="w-3/4 xl:w-4/5">
  6. <template #toolbar>
  7. <Authority>
  8. <a-button type="primary" @click="handleCreate">新增账号</a-button>
  9. </Authority>
  10. <Authority value="api:yt:user:delete">
  11. <Popconfirm title="您确定要批量删除数据" ok-text="确定" cancel-text="取消" @confirm="handleDeleteOrBatchDelete(null)">
  12. <a-button color="error" :disabled="hasBatchDelete"> 批量删除 </a-button>
  13. </Popconfirm>
  14. </Authority>
  15. </template>
  16. <template #status="{ record }">
  17. <Tag :color="record.userStatusEnum === 'NORMAL'
  18. ? 'green'
  19. : record.userStatusEnum === 'DISABLED'
  20. ? 'red'
  21. : 'orange'
  22. ">
  23. {{
  24. record.userStatusEnum === 'NORMAL'
  25. ? '正常'
  26. : record.userStatusEnum === 'DISABLED'
  27. ? '已禁用'
  28. : '已过期'
  29. }}
  30. </Tag>
  31. </template>
  32. <template #SEX="{ record }">
  33. <span>{{ record.SEX ? '男' : '女' }}</span>
  34. </template>
  35. <template #statusT="{ record }">
  36. <Tag :color="record.locked == true ? 'red' : 'green'">
  37. {{ record.locked == true ? '已锁定' : '正常' }}
  38. </Tag>
  39. </template>
  40. <template #action="{ record }">
  41. <TableAction :actions="[
  42. // {
  43. // label: '进入',
  44. // icon: 'ant-design:login-outlined',
  45. // tooltip: '以客户用户身份登录',
  46. // onClick: handleLoginCustomAdmin.bind(null, record),
  47. // ifShow: !isAdmin(role),
  48. // },
  49. // {
  50. // label: '用户详情',
  51. // // auth: 'api:yt:user:get',
  52. // icon: 'clarity:info-standard-line',
  53. // tooltip: '用户详情',
  54. // onClick: handleView.bind(null, record),
  55. // ifShow: record.level != 0,
  56. // },
  57. // {
  58. // label: '编辑',
  59. // // auth: 'api:yt:user:update',
  60. // icon: 'clarity:note-edit-line',
  61. // tooltip: '编辑',
  62. // onClick: handleEdit.bind(null, record),
  63. // ifShow: record.level != 0,
  64. // },
  65. {
  66. label: '权限设置',
  67. icon: 'ant-design:key-outlined',
  68. onClick: power.bind(null, record),
  69. },
  70. {
  71. label: '删除',
  72. // auth: 'api:yt:user:delete',
  73. icon: 'ant-design:delete-outlined',
  74. color: 'error',
  75. tooltip: '删除',
  76. ifShow: record.level != 0,
  77. popConfirm: {
  78. title: '是否确认删除',
  79. confirm: handleDeleteOrBatchDelete.bind(null, record),
  80. },
  81. },
  82. ]" :drop-down-actions="[
  83. // {
  84. // label: '删除',
  85. // // auth: 'api:yt:user:delete',
  86. // icon: 'ant-design:delete-outlined',
  87. // color: 'error',
  88. // tooltip: '删除',
  89. // ifShow: record.level != 0,
  90. // popConfirm: {
  91. // title: '是否确认删除',
  92. // confirm: handleDeleteOrBatchDelete.bind(null, record),
  93. // },
  94. // },
  95. // {
  96. // label: '解锁',
  97. // auth: 'api:yt:user:delete',
  98. // icon: 'ant-design:key-outlined',
  99. // color: 'error',
  100. // tooltip: '解锁',
  101. // ifShow: record.level != 0,
  102. // popConfirm: {
  103. // title: '是否确认解锁',
  104. // confirm: unlock.bind(null, record),
  105. // },
  106. // },
  107. ]" />
  108. </template>
  109. </BasicTable>
  110. <AccountModal @register="registerModal" @success="handleSuccess" />
  111. </PageWrapper>
  112. <PowerDrawer @register="registerDrawer" @success="handleSuccess"></PowerDrawer>
  113. </div>
  114. </template>
  115. <script lang="ts">
  116. import { defineComponent, reactive, nextTick, toRaw } from 'vue';
  117. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  118. import { deleteUser, getAccountList, alterUnlock } from '/@/api/system/system';
  119. import { PageWrapper } from '/@/components/Page';
  120. import { useResetOrganizationTree, OrganizationIdTree } from '/@/views/common/organizationIdTree';
  121. import { Tag, Popconfirm } from 'ant-design-vue';
  122. import { useModal } from '/@/components/Modal';
  123. import AccountModal from './AccountModal.vue';
  124. import { columns, searchFormSchema } from './account.data';
  125. import { useGo } from '/@/hooks/web/usePage';
  126. import { useBatchDelete } from '/@/hooks/web/useBatchDelete';
  127. import { Authority } from '/@/components/Authority';
  128. import { getMyInfo, getPermCode, getUserToken } from '/@/api/sys/user';
  129. import { useUserStore } from '/@/store/modules/user';
  130. import { usePermissionStore } from '/@/store/modules/permission';
  131. import { router } from '/@/router';
  132. import { RoleEnum } from '/@/enums/roleEnum';
  133. import { RouteRecordRaw } from 'vue-router';
  134. import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic';
  135. import { PageEnum } from '/@/enums/pageEnum';
  136. import { getAuthCache } from '/@/utils/auth';
  137. import { USER_INFO_KEY } from '/@/enums/cacheEnum';
  138. import { isAdmin } from '/@/enums/roleEnum';
  139. import { useDrawer } from '/@/components/Drawer';
  140. import PowerDrawer from './PowerDrawer.vue';
  141. export default defineComponent({
  142. name: 'AccountManagement',
  143. components: {
  144. BasicTable,
  145. PageWrapper,
  146. OrganizationIdTree,
  147. AccountModal,
  148. TableAction,
  149. Tag,
  150. Authority,
  151. Popconfirm,
  152. PowerDrawer,
  153. },
  154. setup() {
  155. const userInfo: any = getAuthCache(USER_INFO_KEY);
  156. const role: string = userInfo?.roles[0];
  157. const [registerDrawer, { openDrawer }] = useDrawer();
  158. const go = useGo();
  159. const [registerModal, { openModal }] = useModal();
  160. let searchInfo = reactive<Recordable>({});
  161. const { organizationIdTreeRef, resetFn } = useResetOrganizationTree(searchInfo);
  162. const [registerTable, { reload, setProps }] = useTable({
  163. title: '账号列表',
  164. api: getAccountList,
  165. rowKey: 'id',
  166. columns,
  167. searchInfo,
  168. formConfig: {
  169. labelWidth: 120,
  170. schemas: searchFormSchema,
  171. // autoSubmitOnEnter: true,
  172. resetFunc: resetFn,
  173. },
  174. useSearchForm: true,
  175. showTableSetting: true,
  176. bordered: true,
  177. actionColumn: {
  178. width: 240,
  179. title: '操作',
  180. dataIndex: 'action',
  181. slots: { customRender: 'action' },
  182. fixed: 'right',
  183. },
  184. tableSetting: {
  185. redo: true,
  186. size: true,
  187. setting: false,
  188. fullScreen: false
  189. },
  190. });
  191. const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions } = useBatchDelete(
  192. deleteUser,
  193. handleSuccess,
  194. setProps
  195. );
  196. nextTick(() => {
  197. setProps(selectionOptions);
  198. });
  199. function handleCreate() {
  200. openModal(true, {
  201. isUpdate: false,
  202. });
  203. }
  204. function unlock(data) {
  205. alterUnlock(data.tbUser).then(() => {
  206. reload();
  207. });
  208. }
  209. function handleEdit(record: Recordable) {
  210. openModal(true, {
  211. record,
  212. isUpdate: true,
  213. });
  214. }
  215. function handleSuccess() {
  216. reload();
  217. }
  218. function handleSelect(organization) {
  219. searchInfo.organizationId = organization;
  220. reload();
  221. }
  222. function handleView(record: Recordable) {
  223. go('/system/account_detail/' + record.id);
  224. }
  225. const userStore = useUserStore();
  226. const permissionStore = usePermissionStore();
  227. async function handleLoginCustomAdmin(record: { tbUser: string; id: string }) {
  228. try {
  229. const { token, refreshToken } = await getUserToken(record.id);
  230. userStore.storeToken(token, refreshToken);
  231. const userInfo = await getMyInfo();
  232. const permissionList = await getPermCode();
  233. permissionStore.setPermCodeList(permissionList);
  234. userStore.setUserInfo(userInfo);
  235. userStore.setRoleList(userInfo.roles as RoleEnum[]);
  236. const routes = await permissionStore.buildRoutesAction();
  237. routes.forEach((route) => {
  238. router.addRoute(route as unknown as RouteRecordRaw);
  239. });
  240. router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw);
  241. permissionStore.setDynamicAddedRoute(true);
  242. go(PageEnum.BASE_HOME);
  243. } catch (error) {
  244. } finally {
  245. }
  246. }
  247. function power(record: Recordable) {
  248. openDrawer(true, {
  249. record,
  250. isUpdate: true,
  251. });
  252. }
  253. return {
  254. registerDrawer,
  255. power,
  256. handleLoginCustomAdmin,
  257. registerTable,
  258. registerModal,
  259. handleCreate,
  260. handleEdit,
  261. handleSuccess,
  262. handleSelect,
  263. handleView,
  264. unlock,
  265. organizationIdTreeRef,
  266. hasBatchDelete,
  267. handleDeleteOrBatchDelete,
  268. isAdmin,
  269. role,
  270. };
  271. },
  272. });
  273. </script>