index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="24" class="one">
  6. <!-- <el-form
  7. :model="queryParams"
  8. ref="queryForm"
  9. :inline="true"
  10. v-show="showSearch"
  11. label-width="68px"
  12. >
  13. <el-form-item label="用户名称" prop="userName">
  14. <el-input
  15. v-model="queryParams.userName"
  16. placeholder="请输入用户名称"
  17. clearable
  18. size="small"
  19. style="width: 240px"
  20. @keyup.enter.native="handleQuery"
  21. />
  22. </el-form-item>
  23. <el-form-item label="手机号码" prop="phonenumber">
  24. <el-input
  25. v-model="queryParams.phonenumber"
  26. placeholder="请输入手机号码"
  27. clearable
  28. size="small"
  29. style="width: 240px"
  30. @keyup.enter.native="handleQuery"
  31. />
  32. </el-form-item>
  33. <el-form-item>
  34. <el-button
  35. type="primary"
  36. icon="el-icon-search"
  37. size="mini"
  38. @click="handleQuery"
  39. >搜索</el-button
  40. >
  41. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
  42. >重置</el-button
  43. >
  44. </el-form-item>
  45. </el-form> -->
  46. </el-col>
  47. <el-col :span="24" class="two">
  48. <el-col :span="24" class="two_1">
  49. <el-button
  50. type="primary"
  51. plain
  52. icon="el-icon-plus"
  53. size="mini"
  54. @click="handleAdd"
  55. >新增</el-button
  56. >
  57. </el-col>
  58. <el-col :span="24" class="two_2">
  59. <el-table
  60. :data="list"
  61. border
  62. style="width: 100%"
  63. :header-cell-style="{ 'text-align': 'center' }"
  64. :cell-style="{ 'text-align': 'center' }"
  65. >
  66. <el-table-column
  67. prop="userName"
  68. label="用户名称"
  69. show-overflow-tooltip
  70. >
  71. </el-table-column>
  72. <el-table-column
  73. prop="nickName"
  74. label="用户昵称"
  75. show-overflow-tooltip
  76. >
  77. </el-table-column>
  78. <el-table-column
  79. prop="phonenumber"
  80. label="手机号码"
  81. show-overflow-tooltip
  82. >
  83. </el-table-column>
  84. <el-table-column label="操作">
  85. <template slot-scope="scope">
  86. <el-button
  87. size="mini"
  88. type="text"
  89. icon="el-icon-edit"
  90. @click="toEdit(scope.row)"
  91. >修改</el-button
  92. >
  93. <el-button
  94. size="mini"
  95. type="text"
  96. icon="el-icon-delete"
  97. @click="toDel(scope.row)"
  98. >删除</el-button
  99. >
  100. <el-button
  101. size="mini"
  102. type="text"
  103. icon="el-icon-key"
  104. @click="toPwd(scope.row)"
  105. >重置</el-button
  106. >
  107. </template>
  108. </el-table-column>
  109. </el-table>
  110. <el-col :span="24" class="page">
  111. <el-pagination
  112. @size-change="handleSizeChange"
  113. @current-change="handleCurrentChange"
  114. :current-page="currentPage"
  115. :page-sizes="[10, 20, 30, 50]"
  116. :page-size="limit"
  117. layout="total, sizes, prev, pager, next, jumper"
  118. :total="total"
  119. background
  120. >
  121. </el-pagination>
  122. </el-col>
  123. </el-col>
  124. </el-col>
  125. </el-col>
  126. </el-row>
  127. <el-dialog
  128. :title="dialog.title"
  129. :visible.sync="dialog.show"
  130. width="40%"
  131. :before-close="toClose"
  132. :close-on-click-modal="false"
  133. custom-class="dialog"
  134. >
  135. <div class="info">
  136. <form-1
  137. :form="form"
  138. :deptOptions="deptOptions"
  139. :sexOptions="sexOptions"
  140. :statusOptions="statusOptions"
  141. :postOptions="postOptions"
  142. :roleOptions="roleOptions"
  143. @onSubmit="onSubmit"
  144. @resetForm="toClose"
  145. ></form-1>
  146. </div>
  147. </el-dialog>
  148. </div>
  149. </template>
  150. <script>
  151. import {
  152. listUser,
  153. getUser,
  154. delUser,
  155. addUser,
  156. updateUser,
  157. resetUserPwd,
  158. } from "@/api/system/user";
  159. import form1 from "./parts/form-1.vue";
  160. import { treeselect } from "@/api/system/dept";
  161. import Treeselect from "@riophae/vue-treeselect";
  162. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  163. import { mapState, mapGetters, createNamespacedHelpers } from "vuex";
  164. const { mapActions: merits_user } = createNamespacedHelpers("merits_user");
  165. const { mapActions: role_relation } = createNamespacedHelpers("role_relation");
  166. export default {
  167. name: "index",
  168. props: {},
  169. components: { form1, Treeselect },
  170. data: function () {
  171. return {
  172. // 显示搜索条件
  173. showSearch: true,
  174. // 查询
  175. queryParams: {},
  176. // 列表
  177. list: [],
  178. total: 0,
  179. dialog: { title: "新增用户", show: false },
  180. // 添加
  181. form: { status: "0" },
  182. // 默认密码
  183. initPassword: undefined,
  184. // 归属部门
  185. deptOptions: undefined,
  186. // 性别状态字典
  187. sexOptions: [],
  188. // 状态数据字典
  189. statusOptions: [],
  190. // 岗位选项
  191. postOptions: [],
  192. // 角色选项
  193. roleOptions: [],
  194. // 分页
  195. currentPage: 1,
  196. limit: 10,
  197. };
  198. },
  199. created() {
  200. this.searchOther();
  201. this.getList();
  202. this.getConfigKey("sys.user.initPassword").then((response) => {
  203. this.initPassword = response.msg;
  204. });
  205. },
  206. methods: {
  207. ...merits_user(["query", "create", "delete"]),
  208. ...role_relation({ roleQuery: "query" }),
  209. async getList({ skip = 0, limit = this.limit, ...info } = {}) {
  210. info.superior_id = this.user_id;
  211. let res = await this.query({ skip, limit, ...info });
  212. if (this.$checkRes(res)) {
  213. this.$set(this, `list`, res.data);
  214. this.$set(this, `total`, res.total);
  215. }
  216. },
  217. // 修改信息
  218. toEdit(row) {
  219. const userId = row.userId;
  220. getUser(userId).then((response) => {
  221. this.form = response.data;
  222. this.postOptions = response.posts;
  223. this.form.postIds = response.postIds;
  224. this.form.roleIds = response.roleIds;
  225. this.dialog = { title: "修改信息", show: true };
  226. });
  227. },
  228. // 删除信息
  229. async toDel(row) {
  230. const userIds = row.userId || this.ids;
  231. this.$confirm("是否确认删除数据项吗?", "警告", {
  232. confirmButtonText: "确定",
  233. cancelButtonText: "取消",
  234. type: "warning",
  235. })
  236. .then(function () {
  237. return delUser(userIds);
  238. })
  239. .then(async () => {
  240. let res = await this.delete(userIds);
  241. if (this.$checkRes(res)) {
  242. this.handleQuery();
  243. this.msgSuccess("删除成功");
  244. }
  245. })
  246. .catch(() => {});
  247. },
  248. // 重置密码
  249. toPwd(row) {
  250. this.$prompt('请输入"' + row.userName + '"的新密码', "提示", {
  251. confirmButtonText: "确定",
  252. cancelButtonText: "取消",
  253. })
  254. .then(({ value }) => {
  255. resetUserPwd(row.userId, value).then((response) => {
  256. this.msgSuccess("修改成功,新密码是:" + value);
  257. });
  258. })
  259. .catch(() => {});
  260. },
  261. /** 搜索按钮操作 */
  262. handleQuery() {
  263. this.getList();
  264. },
  265. /** 重置按钮操作 */
  266. resetQuery() {
  267. this.dateRange = [];
  268. this.resetForm("queryForm");
  269. this.handleQuery();
  270. },
  271. // 新增
  272. handleAdd() {
  273. this.form.password = this.initPassword;
  274. this.dialog = { title: "新增用户", show: true };
  275. },
  276. // 提交
  277. onSubmit({ data }) {
  278. if (data && data.userId) {
  279. delete data.createTime;
  280. delete data.updateTime;
  281. updateUser(data).then((response) => {
  282. this.msgSuccess("修改成功");
  283. this.toClose();
  284. this.getList();
  285. });
  286. } else {
  287. addUser(data).then((response) => {
  288. if (response.code === 200) {
  289. listUser(this.addDateRange({ userName: data.userName })).then(
  290. async (res) => {
  291. let p1 = res.rows.find((i) => i.userName === data.userName);
  292. if (p1) {
  293. let p2 = { user_id: p1.userId, superior_id: this.user_id };
  294. let p3 = await this.create(p2);
  295. if (this.$checkRes(p3)) {
  296. this.msgSuccess("新增成功");
  297. this.toClose();
  298. this.getList();
  299. }
  300. }
  301. }
  302. );
  303. }
  304. });
  305. }
  306. },
  307. // 其他信息
  308. async searchOther() {
  309. treeselect().then((response) => {
  310. this.deptOptions = response.data;
  311. });
  312. this.getDicts("sys_user_sex").then((response) => {
  313. this.sexOptions = response.data;
  314. });
  315. this.getDicts("sys_normal_disable").then((response) => {
  316. this.statusOptions = response.data;
  317. });
  318. getUser().then(async (response) => {
  319. this.postOptions = response.posts;
  320. let res = await this.roleQuery();
  321. if (this.$checkRes(res)) {
  322. let levelInfo = res.data.relation.find(
  323. (i) => i.roleKey == this.roles[0]
  324. );
  325. if (levelInfo) {
  326. let nextLevel = parseInt(levelInfo.level) + 1;
  327. let p1 = res.data.relation.filter((i) => i.level == nextLevel)[0];
  328. let roleList = response.roles.filter(
  329. (i) => i.roleKey == p1.roleKey
  330. );
  331. if (roleList) this.roleOptions = roleList;
  332. }
  333. }
  334. });
  335. },
  336. // 关闭
  337. toClose() {
  338. this.form = { status: "0" };
  339. this.dialog = { title: "新增用户", show: false };
  340. },
  341. // 分页
  342. handleSizeChange(val) {
  343. this.$set(this, `limit`, val);
  344. this.getList();
  345. },
  346. handleCurrentChange(val) {
  347. this.getList({ skip: (val - 1) * this.limit });
  348. },
  349. },
  350. computed: {
  351. ...mapGetters(["user_id", "roles"]),
  352. },
  353. metaInfo() {
  354. return { title: this.$route.meta.title };
  355. },
  356. watch: {
  357. test: {
  358. deep: true,
  359. immediate: true,
  360. handler(val) {},
  361. },
  362. },
  363. };
  364. </script>
  365. <style lang="scss" scoped>
  366. .main {
  367. padding: 25px 30px 30px;
  368. .two {
  369. .two_1 {
  370. margin: 0 0 10px 0;
  371. }
  372. }
  373. }
  374. .page {
  375. text-align: right;
  376. margin: 10px 0 0 0;
  377. }
  378. .dialog {
  379. .info {
  380. height: 430px;
  381. overflow-y: auto;
  382. }
  383. }
  384. </style>