index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 @register="registerModal" @onSubmit="onSubmit" />
  35. </div>
  36. </template>
  37. <script>
  38. import { defineComponent, reactive, ref, toRefs, computed, onMounted, watch, createVNode } from 'vue';
  39. // 导入表格组件,表格事件
  40. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  41. import AccountModal1 from './AccountModal1.vue';
  42. // 操作用户数据api
  43. import { deleteUser, getAccountList } from '/@/api/system/system';
  44. import { useModal } from '/@/components/Modal';
  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 [registerModal, { openModal }] = useModal();
  56. const getAllData = () => {
  57. return new Promise((resolve) => {
  58. let params = {
  59. keyStr: '',
  60. page: 1,
  61. pageSize: 100000000,
  62. }
  63. getAccountList(params).then(res => {
  64. if (res.items?.length) {
  65. resolve(res.items)
  66. } else {
  67. message.info('未查询到用户数据')
  68. resolve([])
  69. }
  70. })
  71. })
  72. }
  73. const columns = [
  74. {
  75. title: '用户姓名',
  76. dataIndex: 'NAME',
  77. align: 'center'
  78. },
  79. {
  80. title: '登录名',
  81. dataIndex: 'LOGIN_NAME',
  82. align: 'center'
  83. },
  84. // {
  85. // title: '用户ID',
  86. // dataIndex: 'EMPLOYEE_ID',
  87. // align: 'center'
  88. // },
  89. {
  90. title: '性别',
  91. dataIndex: 'SEX',
  92. align: 'center',
  93. slots: { customRender: 'SEX' },
  94. },
  95. ]
  96. //注册表格
  97. const [
  98. registerTable,
  99. { reload },
  100. ] = useTable({
  101. title: '用户列表', //'菜单列表'
  102. api: getAllData, //加载数据
  103. // dataSource: [],
  104. columns: columns,
  105. useSearchForm: false, //开启搜索区域
  106. bordered: true,
  107. striped: false,
  108. showTableSetting: true, // 显示表格设置
  109. tableSetting: {
  110. redo: true,
  111. size: true,
  112. setting: false,
  113. fullScreen: false
  114. },
  115. canResize: false,
  116. showIndexColumn: true,
  117. pagination: {
  118. // pageSize: 10,
  119. hideOnSinglePage: false
  120. },
  121. actionColumn: {
  122. width: 100,
  123. title: '操作',
  124. dataIndex: 'action',
  125. slots: { customRender: 'action' },
  126. },
  127. // rowSelection: {
  128. // type: 'checkbox',
  129. // },
  130. });
  131. const formData = ref(null)
  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. openModal(true, {
  150. status:'add',
  151. title: '新增用户',
  152. form: {
  153. loginName: "",
  154. userName: "",
  155. pwd: '',
  156. mobile: "",
  157. sex: '0',
  158. sszw: "",
  159. ssgw: "",
  160. userjs: [],
  161. userid: ""
  162. }
  163. })
  164. }
  165. // 编辑
  166. const handleEdit = (record) => {
  167. getUserInfoByLoginCode(record.LOGIN_NAME).then(res => {
  168. if (res.user?.userid) {
  169. getUserIdInfo(res.user.userid).then(roleRes => {
  170. //组合信息传给修改弹窗
  171. formData.value = {
  172. loginName: res.user.loginName,
  173. userName: res.user.userName,
  174. pwd: "",
  175. mobile: res.user.mobile,
  176. sex: res.user.sex,
  177. ssjg: res.department[0]?.departid || '',
  178. sszw: res.zw[0]?.departid || '',
  179. ssgw: res.gw[0]?.id || '',
  180. userjsArr: roleRes,
  181. userjs: roleRes.join(';'),
  182. userid: res.user.userid
  183. }
  184. openModal(true, {
  185. title: '修改用户',
  186. status:'edit',
  187. form: {
  188. loginName: res.user.loginName,
  189. userName: res.user.userName,
  190. pwd: "",
  191. mobile: res.user.mobile,
  192. sex: res.user.sex,
  193. ssjg: res.department[0]?.departid || '',
  194. sszw: res.zw[0]?.departid || '',
  195. ssgw: res.gw[0]?.id || '',
  196. userjsArr: roleRes,
  197. userjs: roleRes.join(';'),
  198. userid: res.user.userid
  199. }
  200. })
  201. })
  202. } else {
  203. message.error('用户信息查询失败')
  204. }
  205. })
  206. }
  207. // 删除
  208. const handleDelete = (record) => {
  209. if (record.EMPLOYEE_ID === session.getItem('userId')) {
  210. message.error('不能删除当前登录用户');
  211. return;
  212. }
  213. Modal.confirm({
  214. title: '提示',
  215. icon: createVNode(ExclamationCircleOutlined),
  216. content: '确定删除该用户数据?',
  217. centered: true,
  218. okText: '确定',
  219. okType: 'danger',
  220. cancelText: '取消',
  221. onOk: (() => {
  222. deleteUser(record.EMPLOYEE_ID).then(res => {
  223. reload();
  224. })
  225. })
  226. });
  227. }
  228. //新增或修改的提交
  229. const onSubmit = () => {
  230. reload();
  231. }
  232. return {
  233. formData,
  234. registerTable,
  235. handlePermissionEdit,
  236. registerModal,
  237. handleAdd,
  238. handleEdit,
  239. handleDelete,
  240. onSubmit
  241. };
  242. },
  243. });
  244. </script>
  245. <style lang="less" scoped>
  246. .p-4 {
  247. height: 100%;
  248. .account-body {
  249. padding: 0 20px;
  250. width: 100%;
  251. height: 100%;
  252. background-color: #fff;
  253. .basic-table {
  254. height: 100%;
  255. ::v-deep .ant-table-title {
  256. padding: 0 !important;
  257. .vben-basic-title {
  258. font-family: '阿里巴巴普惠体 2.0';
  259. font-size: 16px;
  260. font-weight: bold;
  261. color: #333333;
  262. }
  263. }
  264. }
  265. }
  266. }
  267. </style>