index.vue 8.9 KB

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