UserManger.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. <template>
  2. <div>
  3. <div class="search-box">
  4. <div class="filter-box">
  5. <el-input
  6. size="small"
  7. placeholder="请输入用户名"
  8. @change="checkList()"
  9. clearable
  10. v-model="username"
  11. >
  12. <i slot="suffix" class="el-input__icon el-icon-search"></i>
  13. </el-input>
  14. </div>
  15. <el-button v-if="have_type == 0 || staff == 1" type="success" size="mini"
  16. ><a style="color: #fff" href="systemmanage_user_add"
  17. >添加新用户</a
  18. ></el-button
  19. >
  20. </div>
  21. <el-row :gutter="10">
  22. <el-col
  23. :xs="24"
  24. :sm="24"
  25. :md="12"
  26. :lg="6"
  27. :xl="6"
  28. v-for="item in userList"
  29. :key="item.uid"
  30. >
  31. <el-card class="box-card pad0">
  32. <div class="img-box">
  33. <img src="@/assets/images/systemManger/user.png" />
  34. <p>{{ item.username }}</p>
  35. </div>
  36. <div class="detail">
  37. <p>
  38. 模块类型
  39. <span v-if="item.user_type == '1'">农业植保监测系统</span>
  40. <span v-if="item.user_type == '2'">农业气象监测系统</span>
  41. <span v-if="item.user_type == '3'">环境灾害预警系统</span>
  42. <span v-if="item.user_type == '4'">农产品溯源系统</span>
  43. <span v-if="item.user_type == '5'">可视农业应用系统</span>
  44. <span v-if="item.user_type == '6'">苗情监测应用系统</span>
  45. </p>
  46. <p>
  47. 用户类型
  48. <span v-if="item.user_have_type == '1'">普通用户</span>
  49. <span v-if="item.user_have_type == '0'">管理员</span>
  50. </p>
  51. <p>
  52. 站点名称
  53. <span>{{ item.site || "无" }}</span>
  54. </p>
  55. <p>
  56. 站点地址
  57. <span
  58. >{{ item.user_pro }} {{ item.user_city }}
  59. {{ item.user_area }}</span
  60. >
  61. </p>
  62. <p>
  63. 标题
  64. <span>{{ item.user_header || "--" }}</span>
  65. </p>
  66. <p>
  67. logo
  68. <span
  69. ><img style="width: 46px; height: 32px" :src="item.logo" alt=""
  70. /></span>
  71. </p>
  72. </div>
  73. <div class="btn">
  74. <el-button size="small" type="success" @click="edit(item)" plain
  75. >用户编辑</el-button
  76. >
  77. <template v-if="have_type == 0 || staff == 1">
  78. <el-button
  79. size="small"
  80. v-if="item.user_have_type == '1'"
  81. type="success"
  82. @click="allotEquip(item.id, item.username)"
  83. plain
  84. >分配设备</el-button
  85. >
  86. <el-button
  87. size="small"
  88. v-if="item.user_have_type == '1'"
  89. type="success"
  90. @click="delUser(item.id, item.username)"
  91. plain
  92. >删除用户</el-button
  93. >
  94. </template>
  95. <el-button
  96. type="success"
  97. size="small"
  98. @click="resetPassword(item.id, item.username)"
  99. plain
  100. >重置密码</el-button
  101. >
  102. </div>
  103. </el-card>
  104. </el-col>
  105. </el-row>
  106. <!-- 暂无数据 -->
  107. <div class="expertDiagnosis_referral_units_not" v-if="userList.length <= 0">
  108. <img
  109. src="@/assets/images/monitor/zanwu.png"
  110. alt
  111. class="expertDiagnosis_referral_units_notImg"
  112. />
  113. </div>
  114. <el-pagination
  115. v-if="userList.length > 0"
  116. background
  117. :page-size="8"
  118. layout="prev, pager, next"
  119. :current-page="page"
  120. :total="totalNum"
  121. @current-change="changePage"
  122. ></el-pagination>
  123. <!-- 重置密码 -->
  124. <el-dialog
  125. title="重置密码"
  126. :visible.sync="resetPassDialogVisible"
  127. width="30%"
  128. @close="resetPassDialogClosed"
  129. >
  130. <el-form
  131. ref="resetPassFormRef"
  132. :model="resetPassForm"
  133. label-width="110px"
  134. :rules="resetPassFormRules"
  135. >
  136. <el-form-item label="用户名 : " prop="username">
  137. <el-input
  138. type="text"
  139. disabled
  140. v-model="resetPassForm.username"
  141. ></el-input>
  142. </el-form-item>
  143. <el-form-item label="新密码 : " prop="pass">
  144. <el-input type="password" v-model="resetPassForm.pass"></el-input>
  145. </el-form-item>
  146. <el-form-item label="确认新密码 : " prop="checkPass">
  147. <el-input
  148. type="password"
  149. v-model="resetPassForm.checkPass"
  150. ></el-input>
  151. </el-form-item>
  152. </el-form>
  153. <span slot="footer" class="dialog-footer">
  154. <el-button @click="resetPassDialogVisible = false">取 消</el-button>
  155. <el-button type="primary" @click="resetPassSubm">确认</el-button>
  156. </span>
  157. </el-dialog>
  158. <!-- 用户编辑 -->
  159. <el-dialog
  160. title="用户信息编辑"
  161. :visible.sync="editUserDialogVisible"
  162. width="500px"
  163. @close="editUserDialogClosed"
  164. >
  165. <el-form ref="editUserFormRef" :model="editUserForm" label-width="80px">
  166. <el-form-item label="用户名 : ">
  167. <el-input v-model="editUserForm.username" disabled></el-input>
  168. </el-form-item>
  169. <el-form-item label="标题 : ">
  170. <el-input
  171. maxlength="11"
  172. v-model="editUserForm.user_header"
  173. ></el-input>
  174. </el-form-item>
  175. <el-form-item label="logo : ">
  176. <el-upload
  177. class="avatar-uploader"
  178. action
  179. :auto-upload="false"
  180. :show-file-list="false"
  181. :on-change="changeUpload"
  182. :before-upload="beforeAvatarUpload"
  183. >
  184. <img
  185. v-if="editUserForm.logo"
  186. :src="editUserForm.logo"
  187. class="avatar"
  188. />
  189. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  190. </el-upload>
  191. </el-form-item>
  192. <el-form-item label="站点名称 : ">
  193. <el-input maxlength="16" v-model="editUserForm.site"></el-input>
  194. </el-form-item>
  195. <el-form-item label="站点位置 : ">
  196. <div class="block">
  197. <el-cascader
  198. placeholder="搜索:河南"
  199. v-model="cityValue"
  200. :options="cityData"
  201. :props="props"
  202. @change="handleChange"
  203. filterable
  204. >
  205. </el-cascader>
  206. </div>
  207. </el-form-item>
  208. </el-form>
  209. <span slot="footer" class="dialog-footer">
  210. <el-button @click="editUserDialogVisible = false">取 消</el-button>
  211. <el-button type="primary" @click="editUserSubm">确认</el-button>
  212. </span>
  213. </el-dialog>
  214. </div>
  215. </template>
  216. <script>
  217. import cityData from "./citydata.js";
  218. export default {
  219. data() {
  220. var checkMobile = (rule, value, callback) => {
  221. const regMobile = /^1\d{10}$/;
  222. if (regMobile.test(value)) {
  223. callback();
  224. } else {
  225. // 返回一个错误提示
  226. callback(new Error("请输入合法的手机号码"));
  227. }
  228. };
  229. var validatePass = (rule, value, callback) => {
  230. if (value === "") {
  231. callback(new Error("请输入新密码"));
  232. } else {
  233. if (this.resetPassForm.checkPass !== "") {
  234. this.$refs.resetPassFormRef.validateField("checkPass");
  235. }
  236. callback();
  237. }
  238. };
  239. var validatePass2 = (rule, value, callback) => {
  240. if (value === "") {
  241. callback(new Error("请再次输入密码"));
  242. } else if (value !== this.resetPassForm.pass) {
  243. callback(new Error("两次输入密码不一致!"));
  244. } else {
  245. callback();
  246. }
  247. };
  248. return {
  249. zanwu: "/images/expertDiagnosis/zanwu.png",
  250. role: "", //筛选项 角色类型
  251. userTypeCheck: "", //筛选项 用户类型
  252. username: "", //筛选项
  253. roleList: [],
  254. page: 1,
  255. userList: [],
  256. userGroupList: [],
  257. totalNum: 0,
  258. //省市县
  259. areaList: [],
  260. resetPassDialogVisible: false,
  261. addUserDialogVisible: false,
  262. editUserDialogVisible: false,
  263. resetPassForm: {
  264. username: "",
  265. uid: "",
  266. pass: "",
  267. checkPass: "",
  268. },
  269. addUserForm: {
  270. username: "",
  271. mobile: "",
  272. pass: "",
  273. role_id: "",
  274. user_type: "",
  275. pcd: "",
  276. user_area: "",
  277. cs_user: false, //1为普通用户
  278. user_group_id: "", //用户组id
  279. },
  280. cityData,
  281. cityValue: [],
  282. props: {
  283. expandTrigger: "hover",
  284. value: "value",
  285. },
  286. editUserForm: {},
  287. //控制省/市/区显示
  288. editIsShow: false,
  289. //添加用户规则
  290. addUserFormRules: {
  291. username: [
  292. { required: true, message: "请填写用户名", trigger: "blur" },
  293. ],
  294. mobile: [
  295. { required: true, trigger: "blur", message: "手机号不能为空" },
  296. { validator: checkMobile, trigger: "blur" },
  297. ],
  298. pass: [{ required: true, message: "请填写用户密码", trigger: "blur" }],
  299. },
  300. //重置密码格规则
  301. resetPassFormRules: {
  302. pass: [
  303. { validator: validatePass, trigger: "blur" },
  304. { required: true, message: "请填写新密码", trigger: "blur" },
  305. ],
  306. checkPass: [
  307. { validator: validatePass2, trigger: "blur" },
  308. { required: true, message: "请确认新密码", trigger: "blur" },
  309. ],
  310. },
  311. have_type: "",
  312. staff: "",
  313. };
  314. },
  315. computed: {
  316. //获取用户类型
  317. userType: function () {
  318. return window.sessionStorage.getItem("myuser_type");
  319. },
  320. },
  321. mounted() {
  322. this.getList();
  323. this.have_type = localStorage.getItem("have_type"); // 0管理员 1用户
  324. this.staff = localStorage.getItem("staff"); // 1是admin
  325. },
  326. methods: {
  327. getList() {
  328. this.$axios({
  329. method: "POST",
  330. url: "user_list",
  331. data: this.qs.stringify({
  332. typelist: 5,
  333. page: this.page,
  334. uname: this.username,
  335. page_size: 8,
  336. }),
  337. }).then((res) => {
  338. this.userList = res.data.userlist;
  339. this.totalNum = res.data.nums;
  340. });
  341. },
  342. // 编辑用户信息
  343. edit(role) {
  344. this.editUserForm = JSON.parse(JSON.stringify(role));
  345. this.editUserDialogVisible = true;
  346. this.cityValue = [
  347. this.editUserForm.user_pro,
  348. this.editUserForm.user_city,
  349. this.editUserForm.user_area,
  350. ];
  351. },
  352. beforeAvatarUpload(file) {
  353. console.log(file);
  354. const isJPG = file.type === "image/jpeg" || file.type === "image/png";
  355. const isLt2M = file.size / 1024 / 1024 < 2;
  356. if (!isJPG) {
  357. this.$message.error("上传头像图片只能是 JPG 和 PNG格式!");
  358. }
  359. if (!isLt2M) {
  360. this.$message.error("上传头像图片大小不能超过 2MB!");
  361. }
  362. return isJPG && isLt2M;
  363. },
  364. changeUpload(file, fileList) {
  365. var form = new FormData();
  366. form.append("img_file", file.raw);
  367. this.$axios({
  368. method: "POST",
  369. url: "base_photo",
  370. data: form,
  371. }).then((res) => {
  372. this.editUserForm.logo = res.data.src;
  373. });
  374. },
  375. handleChange(value) {
  376. console.log(value);
  377. console.log(this.cityValue);
  378. this.editUserForm.user_pro = value[0];
  379. this.editUserForm.user_city = value[1];
  380. if (value[2]) {
  381. this.editUserForm.user_area = value[2];
  382. } else {
  383. this.editUserForm.user_city = value[0].substring(
  384. 0,
  385. value[0].length - 1
  386. );
  387. this.editUserForm.user_area = value[1];
  388. }
  389. },
  390. // 分配设备
  391. allotEquip(id, name) {
  392. window.location.href = "allot?uname=" + name;
  393. },
  394. // 删除普通用户
  395. delUser(id, name) {
  396. this.$confirm("删除用户, 是否继续?", "警告", {
  397. confirmButtonText: "确定",
  398. cancelButtonText: "取消",
  399. type: "warning",
  400. })
  401. .then(() => {
  402. this.$axios({
  403. method: "POST",
  404. url: "del_user",
  405. data: this.qs.stringify({
  406. userid: id,
  407. }),
  408. }).then((res) => {
  409. if (res.data == 1) {
  410. this.getList();
  411. } else {
  412. this.$message({
  413. type: "error",
  414. message: res.data,
  415. });
  416. }
  417. });
  418. })
  419. .catch(() => {
  420. this.$message({
  421. type: "info",
  422. message: "已取消删除",
  423. });
  424. });
  425. },
  426. //密码重置
  427. resetPassword(id, name) {
  428. this.resetPassForm.id = id;
  429. this.resetPassForm.username = name;
  430. this.resetPassDialogVisible = true;
  431. },
  432. resetPassSubm() {
  433. //暂时不用
  434. this.$refs.resetPassFormRef.validate((valid) => {
  435. if (!valid) return;
  436. this.$axios({
  437. method: "POST",
  438. url: "systemmanage_user_list",
  439. data: this.qs.stringify({
  440. id: this.resetPassForm.id,
  441. req: "resetpwd",
  442. userName: this.editUserForm.username,
  443. userpassWord: this.resetPassForm.pass,
  444. userRePassWord: this.resetPassForm.pass,
  445. }),
  446. }).then((res) => {
  447. if (res.data == 0) {
  448. this.$message.success("修改密码成功");
  449. this.resetPassDialogVisible = false;
  450. } else {
  451. this.$message.error(res.data.message);
  452. }
  453. });
  454. });
  455. },
  456. //监听重置密码对话框的关闭事件
  457. resetPassDialogClosed() {
  458. this.$refs.resetPassFormRef.resetFields();
  459. },
  460. changePage(value) {
  461. this.page = value;
  462. this.getList();
  463. },
  464. //添加用户
  465. addUser() {
  466. this.addUserDialogVisible = true;
  467. },
  468. //添加用户提交
  469. addUserSubm() {
  470. this.$refs.addUserFormRef.validate((valid) => {
  471. if (!valid) return;
  472. let cs_user = this.addUserForm.cs_user ? "1" : "";
  473. this.$axios({
  474. method: "POST",
  475. url: "api_gateway?method=user.login.regiest",
  476. data: this.qs.stringify({
  477. username: this.addUserForm.username,
  478. mobile: this.addUserForm.mobile,
  479. password: this.addUserForm.pass,
  480. role_id: this.addUserForm.role_id,
  481. user_type: this.addUserForm.user_type,
  482. pcd: this.addUserForm.pcd,
  483. user_area: this.addUserForm.user_area,
  484. user_group_id: this.addUserForm.user_group_id,
  485. cs_user,
  486. }),
  487. }).then((res) => {
  488. if (res.data.message == "") {
  489. this.$message.success("添加用户成功!");
  490. this.addUserDialogVisible = false;
  491. this.getList();
  492. } else {
  493. this.$message.error(res.data.message);
  494. }
  495. });
  496. });
  497. },
  498. addUserDialogClosed() {
  499. this.$refs.addUserFormRef.resetFields();
  500. },
  501. //修改用户信息提交
  502. editUserSubm() {
  503. this.$refs.editUserFormRef.validate((valid) => {
  504. if (!valid) return;
  505. this.$axios({
  506. method: "POST",
  507. url: "user_detail",
  508. data: this.qs.stringify(this.editUserForm),
  509. }).then((res) => {
  510. if (res.data == 1) {
  511. this.editUserDialogVisible = false;
  512. var curr = localStorage.getItem("username");
  513. if (curr == this.editUserForm.username) {
  514. window.location.reload();
  515. } else {
  516. this.getList();
  517. }
  518. }
  519. });
  520. });
  521. },
  522. editUserDialogClosed() {
  523. this.$refs.editUserFormRef.resetFields();
  524. this.areaList = []; //清空省/市/区
  525. this.editIsShow = false;
  526. },
  527. checkList() {
  528. this.page = 1;
  529. this.getList();
  530. },
  531. },
  532. };
  533. </script>
  534. <style lang='less' scoped>
  535. .search-box {
  536. display: flex;
  537. justify-content: space-between;
  538. margin-bottom: 10px;
  539. .filter-box > div {
  540. margin-right: 15px;
  541. }
  542. .el-input {
  543. width: 200px;
  544. }
  545. .el-date-editor--daterange {
  546. width: 222px;
  547. }
  548. }
  549. .el-card {
  550. .img-box {
  551. text-align: center;
  552. border-bottom: 1px solid #e1e1e1;
  553. padding: 15px 0;
  554. p {
  555. font-size: 14px;
  556. font-weight: 800;
  557. margin-top: 10px;
  558. }
  559. }
  560. .detail {
  561. border-bottom: 1px solid #e1e1e1;
  562. padding: 10px 0;
  563. padding: 0 20px;
  564. p {
  565. display: flex;
  566. justify-content: space-between;
  567. font-size: 13px;
  568. line-height: 34px;
  569. color: #666;
  570. padding: 0 0px;
  571. }
  572. }
  573. .btn {
  574. text-align: center;
  575. padding: 20px 10px;
  576. display: flex;
  577. justify-content: space-around;
  578. button {
  579. // flex: 1;
  580. margin: 0 8px;
  581. border: 1px solid #17bb89;
  582. color: #17bb89;
  583. // border-radius: 4px;
  584. // font-size: 12px;
  585. // padding: 5px 5px;
  586. background: #fff;
  587. cursor: pointer;
  588. i {
  589. font-size: 12px;
  590. margin-right: 2px;
  591. }
  592. }
  593. button:hover {
  594. background: #fff;
  595. border: 1px solid #47d9ad;
  596. color: #47d9ad;
  597. }
  598. }
  599. }
  600. // 暂无数据
  601. .expertDiagnosis_referral_units_not {
  602. width: 272px;
  603. margin: 0 auto;
  604. }
  605. </style>