index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <div class="card-search">
  3. <a-form
  4. ref="formRef"
  5. name="advanced_search"
  6. class="ant-advanced-search-form"
  7. :model="searchParamsState"
  8. >
  9. <a-row :gutter="24">
  10. <a-col :span="6">
  11. <a-form-item label="用户名" :label-col="{ span: 8 }" name="name">
  12. <a-input v-model:value="searchParamsState.name" placeholder="" />
  13. </a-form-item>
  14. </a-col>
  15. <a-col :span="6">
  16. <a-form-item label="帐号" :label-col="{ span: 8 }" name="loginID">
  17. <a-input v-model:value="searchParamsState.loginID" placeholder="" />
  18. </a-form-item>
  19. </a-col>
  20. <a-col :span="6">
  21. <a-form-item label="用户类型" :label-col="{ span: 8 }" name="userType">
  22. <a-select
  23. ref="select"
  24. v-model:value="searchParamsState.userType"
  25. :options="userTypeList"
  26. :field-names="{ label: 'name', value: 'value' }"
  27. :allow-clear="true"
  28. @change="loadData"
  29. >
  30. </a-select>
  31. </a-form-item>
  32. </a-col>
  33. <a-col :span="6" style="text-align: left">
  34. <a-button type="primary" html-type="submit" @click="onFinish">查询</a-button>
  35. <a-button
  36. style="margin: 0 8px"
  37. @click="
  38. () => {
  39. formRef.resetFields();
  40. loadData();
  41. }
  42. "
  43. >重置</a-button
  44. >
  45. </a-col>
  46. </a-row>
  47. <a-row class="edit-operation">
  48. <a-col :span="24" style="text-align: right">
  49. <a-button type="primary" html-type="submit" functioncode="T0199010105" @click="onAdd('')"
  50. >新增</a-button
  51. >
  52. </a-col>
  53. </a-row>
  54. </a-form>
  55. <div class="search-result-list">
  56. <a-table
  57. :columns="columns"
  58. :data-source="dataList"
  59. :scroll="{ x: '100%', y: 500 }"
  60. :pagination="pagination"
  61. :loading="formState.loading"
  62. :row-selection="{ selectedRowKeys: formState.selectedRowKeys, onChange: onSelectChange }"
  63. :row-key="(record) => record.UserID"
  64. bordered
  65. @change="handleTableChange"
  66. >
  67. <template #bodyCell="{ column, text, record }">
  68. <template v-if="column.key === 'operation'">
  69. <div class="table-operation">
  70. <a-button type="link" functioncode="T0199010105" @click="onAdd(record.UserID)"
  71. >编辑</a-button
  72. >
  73. <a-button
  74. type="link"
  75. functioncode="T0199010102"
  76. @click="onUpdateUserStatus(record.UserID, 1)"
  77. >启用</a-button
  78. >
  79. <a-button
  80. type="link"
  81. functioncode="T0199010103"
  82. @click="onUpdateUserStatus(record.UserID, 0)"
  83. >禁用</a-button
  84. >
  85. <a-button type="link" functioncode="T0199010104" @click="onUpdatePassword(record)"
  86. >修改密码</a-button
  87. >
  88. </div>
  89. </template>
  90. </template>
  91. </a-table>
  92. </div>
  93. <UpdatePassword ref="updatePasswordRef"></UpdatePassword>
  94. <UserAdd ref="userAddRef" :load-data="loadData"></UserAdd>
  95. </div>
  96. </template>
  97. <script lang="ts">
  98. import { reactive, ref, computed, defineComponent } from 'vue';
  99. import type { FormInstance, TableColumnsType, TableProps, SelectProps } from 'ant-design-vue';
  100. import { getUserListPage, updateUserStatus } from '@/api/system/user';
  101. import { getSysDictionaryList } from '@/api/system/dictionary';
  102. import UpdatePassword from '@/views/system/users/updatePassword.vue';
  103. import UserAdd from '@/views/system/users/addUser.vue';
  104. import { getPaginationTotalTitle } from '@/utils/common';
  105. export default defineComponent({
  106. name: 'UserList',
  107. components: { UpdatePassword, UserAdd },
  108. setup() {
  109. const modalRoleUserRef = ref();
  110. const modalRoleEditRef = ref();
  111. const formRef = ref<FormInstance>();
  112. const searchParamsState = reactive({
  113. page: 1,
  114. limit: 20,
  115. name: '',
  116. loginID: '',
  117. userType: '',
  118. });
  119. const formState = reactive({
  120. total: 0,
  121. selectedRowKeys: [],
  122. loading: false,
  123. });
  124. const columns: TableColumnsType = [
  125. {
  126. title: '序号',
  127. align: 'center',
  128. width: 80,
  129. key: 'roleID',
  130. customRender: (item) =>
  131. `${searchParamsState.limit * (searchParamsState.page - 1) + item.index + 1}`,
  132. },
  133. { title: '用户名', dataIndex: 'Name', key: 'Name', align: 'center', width: 150 },
  134. { title: '帐号', dataIndex: 'LoginID', key: 'LoginID',align: 'center', width: 150 },
  135. { title: '用户类型', dataIndex: 'UserTypeName', key: 'UserTypeName',align: 'center', width: 150,},
  136. { title: '所属区县/机构/驿站', dataIndex: 'dataRangeNames', key: 'dataRangeNames',align: 'center', width: 150,},
  137. { title: '角色', dataIndex: 'roleName', key: 'roleName',align: 'center', width: 180 },
  138. { title: '账号状态', dataIndex: 'RecordStatus', key: 'RecordStatus',align: 'center', width: 110,
  139. customRender: ({ record }) => (record.RecordStatus == 1 ? '正常' : '禁用'),
  140. },
  141. { title: '操作', key: 'operation', width: 220, align: 'center' },
  142. ];
  143. const pagination = computed(() => ({
  144. total: formState.total,
  145. current: searchParamsState.page,
  146. pageSize: searchParamsState.limit,
  147. showSizeChanger: true,
  148. showTotal: (total) => getPaginationTotalTitle(total),
  149. }));
  150. const dataList = ref([]);
  151. const userTypeList = ref<SelectProps['options']>();
  152. const updatePasswordRef = ref();
  153. const userAddRef = ref();
  154. const onSelectChange = (selectedRowKeys: any) => {
  155. formState.selectedRowKeys = selectedRowKeys;
  156. };
  157. const handleTableChange: TableProps['onChange'] = (pag: {
  158. pageSize: number;
  159. current: number;
  160. }) => {
  161. searchParamsState.page = pag.current;
  162. searchParamsState.limit = pag.pageSize;
  163. loadData();
  164. };
  165. const onFinish = () => {
  166. loadData();
  167. };
  168. const onAdd = (userId) => {
  169. userAddRef.value.show(userId);
  170. /*loadData();*/
  171. };
  172. const onUpdateUserStatus = async function (userID, status) {
  173. await updateUserStatus({ userId: userID, status });
  174. await loadData();
  175. };
  176. const onUpdatePassword = (item) => {
  177. updatePasswordRef.value.show(item.UserID, item.Name, item.LoginID, false);
  178. };
  179. const loadData = async function () {
  180. formState.loading = true;
  181. const result: any = await getUserListPage(searchParamsState);
  182. dataList.value = result.list;
  183. console.log('dataList', dataList.value);
  184. formState.total = result.total;
  185. formState.loading = false;
  186. };
  187. const loadUserTypeList = () => {
  188. getSysDictionaryList('UserType').then((data) => {
  189. userTypeList.value = data;
  190. });
  191. };
  192. return {
  193. modalRoleUserRef,
  194. modalRoleEditRef,
  195. formRef,
  196. loadData,
  197. loadUserTypeList,
  198. searchParamsState,
  199. formState,
  200. columns,
  201. pagination,
  202. dataList,
  203. userTypeList,
  204. onSelectChange,
  205. handleTableChange,
  206. onAdd,
  207. onFinish,
  208. onUpdateUserStatus,
  209. onUpdatePassword,
  210. updatePasswordRef,
  211. userAddRef,
  212. };
  213. },
  214. created() {
  215. this.loadData();
  216. this.loadUserTypeList();
  217. },
  218. activated() {
  219. if (history.state.params?.reload) this.loadData();
  220. },
  221. });
  222. </script>
  223. <style lang="less" scoped></style>