index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <div class="p-4">
  3. <div class="account-body">
  4. <BasicTable @register="registerTable" class="basic-table">
  5. <template #toolbar>
  6. <Button type="primary" @click="handleAdd">
  7. 新增用户
  8. </Button>
  9. <!-- 接口不支持多选后统一绑定角色,所以暂时隐藏 -->
  10. <!-- <Button type="primary" @click="handlePermissionEdit">
  11. 角色绑定
  12. </Button> -->
  13. </template>
  14. <template #SEX="{ record }">
  15. <span>{{ record.SEX ? '男' : '女' }}</span>
  16. </template>
  17. <template #action="{ record }">
  18. <TableAction :actions="[
  19. {
  20. label: '编辑',
  21. tooltip: '编辑',
  22. onClick: handleEdit.bind(null, record),
  23. },
  24. {
  25. label: '删除',
  26. tooltip: '删除',
  27. color: 'error',
  28. onClick: handleDelete.bind(null, record),
  29. },
  30. ]" />
  31. </template>
  32. </BasicTable>
  33. </div>
  34. <AccountModal1 v-if="ifShowModal" :title="modalTitle" :formData="formData" @closeModal="ifShowModal = false"
  35. @onSubmit="onSubmit" />
  36. </div>
  37. </template>
  38. <script>
  39. import { defineComponent, reactive, ref, toRefs, computed, onMounted, watch, createVNode } from 'vue';
  40. // 导入表格组件,表格事件
  41. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  42. import AccountModal1 from './AccountModal1.vue';
  43. // 操作用户数据api
  44. import { deleteUser, getAccountList } from '/@/api/system/system';
  45. import { FormOutlined, ExclamationCircleOutlined } from '@ant-design/icons-vue';
  46. import moment from 'moment';
  47. import { Button, Modal, message } from 'ant-design-vue';
  48. import { getUserInfoByLoginCode } from '/@/api/system/system';
  49. import { getUserIdInfo } from '/@/api/sys/user';
  50. import { session } from '/@/utils/Memory';
  51. export default defineComponent({
  52. name: 'account',
  53. components: { BasicTable, TableAction, Button, AccountModal1, ExclamationCircleOutlined },
  54. setup() {
  55. const getAllData = () => {
  56. return new Promise((resolve) => {
  57. let params = {
  58. keyStr: '',
  59. page: 1,
  60. pageSize: 100000000,
  61. }
  62. getAccountList(params).then(res => {
  63. if (res.items?.length) {
  64. resolve(res.items)
  65. } else {
  66. message.info('未查询到用户数据')
  67. resolve([])
  68. }
  69. })
  70. })
  71. }
  72. const columns = [
  73. {
  74. title: '用户姓名',
  75. dataIndex: 'NAME',
  76. align: 'center'
  77. },
  78. {
  79. title: '登录名',
  80. dataIndex: 'LOGIN_NAME',
  81. align: 'center'
  82. },
  83. // {
  84. // title: '用户ID',
  85. // dataIndex: 'EMPLOYEE_ID',
  86. // align: 'center'
  87. // },
  88. {
  89. title: '性别',
  90. dataIndex: 'SEX',
  91. align: 'center',
  92. slots: { customRender: 'SEX' },
  93. },
  94. ]
  95. //注册表格
  96. const [
  97. registerTable,
  98. { reload },
  99. ] = useTable({
  100. title: '用户列表', //'菜单列表'
  101. api: getAllData, //加载数据
  102. // dataSource: [],
  103. columns: columns,
  104. useSearchForm: false, //开启搜索区域
  105. bordered: false,
  106. striped: false,
  107. showTableSetting: true, // 显示表格设置
  108. tableSetting: {
  109. redo: true,
  110. size: true,
  111. setting: false,
  112. fullScreen: false
  113. },
  114. canResize: true,
  115. showIndexColumn: true,
  116. pagination: {
  117. // pageSize: 10,
  118. hideOnSinglePage: false
  119. },
  120. actionColumn: {
  121. width: 100,
  122. title: '操作',
  123. dataIndex: 'action',
  124. slots: { customRender: 'action' },
  125. },
  126. // rowSelection: {
  127. // type: 'checkbox',
  128. // },
  129. });
  130. const formData = ref(null)
  131. const ifShowModal = ref(false)
  132. const modalTitle = ref('新增用户')
  133. //绑定权限
  134. const handlePermissionEdit = () => {
  135. }
  136. // 新增
  137. const handleAdd = () => {
  138. formData.value = {
  139. loginName: "",
  140. userName: "",
  141. pwd: '',
  142. mobile: "",
  143. sex: '0',
  144. sszw: "",
  145. ssgw: "",
  146. userjs: [],
  147. userid: ""
  148. }
  149. modalTitle.value = '新增用户'
  150. ifShowModal.value = true
  151. }
  152. // 编辑
  153. const handleEdit = (record) => {
  154. getUserInfoByLoginCode(record.LOGIN_NAME).then(res => {
  155. if (res.user?.userid) {
  156. getUserIdInfo(res.user.userid).then(roleRes => {
  157. //组合信息传给修改弹窗
  158. formData.value = {
  159. loginName: res.user.loginName,
  160. userName: res.user.userName,
  161. pwd: "",
  162. mobile: res.user.mobile,
  163. sex: res.user.sex,
  164. ssjg: res.department[0]?.departid || '',
  165. sszw: res.zw[0]?.departid || '',
  166. ssgw: res.gw[0]?.id || '',
  167. userjsArr: roleRes,
  168. userjs: roleRes.join(';'),
  169. userid: res.user.userid
  170. }
  171. modalTitle.value = '修改用户'
  172. ifShowModal.value = true
  173. })
  174. } else {
  175. message.error('用户信息查询失败')
  176. }
  177. })
  178. }
  179. // 删除
  180. const handleDelete = (record) => {
  181. if(record.EMPLOYEE_ID === session.getItem('userId')){
  182. message.error('不能删除当前登录用户');
  183. return;
  184. }
  185. Modal.confirm({
  186. title: '删除提示',
  187. icon: createVNode(ExclamationCircleOutlined),
  188. content: '确定删除该用户?',
  189. centered: true,
  190. okText: '确定',
  191. okType: 'danger',
  192. cancelText: '取消',
  193. onOk: (() => {
  194. deleteUser(record.EMPLOYEE_ID).then(res => {
  195. reload();
  196. })
  197. })
  198. });
  199. }
  200. //新增或修改的提交
  201. const onSubmit = (e) => {
  202. ifShowModal.value = false
  203. e && reload();
  204. }
  205. return {
  206. formData,
  207. ifShowModal,
  208. modalTitle,
  209. registerTable,
  210. handlePermissionEdit,
  211. handleAdd,
  212. handleEdit,
  213. handleDelete,
  214. onSubmit
  215. };
  216. },
  217. });
  218. </script>
  219. <style lang="less" scoped>
  220. .p-4 {
  221. height: 100%;
  222. .account-body {
  223. padding: 0 20px;
  224. width: 100%;
  225. height: 100%;
  226. background-color: #fff;
  227. .basic-table {
  228. height: 100%;
  229. ::v-deep .ant-table-title {
  230. padding: 0 !important;
  231. .vben-basic-title {
  232. font-family: '阿里巴巴普惠体 2.0';
  233. font-size: 16px;
  234. font-weight: bold;
  235. color: #333333;
  236. }
  237. }
  238. }
  239. }
  240. }
  241. </style>