UserManger.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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 type="success" @click="edit(item)" plain
  75. >用户编辑</el-button
  76. >
  77. <el-button
  78. type="success"
  79. @click="resetPassword(item.id, item.username)"
  80. plain
  81. >重置密码</el-button
  82. >
  83. <!-- <a @click="edit(item)">
  84. <i class="iconfont icon-iconfontedit"></i>编辑
  85. </a>
  86. <a @click="resetPassword(item.uid, item.username)">
  87. <i class="iconfont icon-mima"></i>密码
  88. </a> -->
  89. </div>
  90. </el-card>
  91. </el-col>
  92. </el-row>
  93. <!-- 暂无数据 -->
  94. <div class="expertDiagnosis_referral_units_not" v-if="userList.length <= 0">
  95. <img
  96. src="@/assets/images/monitor/zanwu.png"
  97. alt
  98. class="expertDiagnosis_referral_units_notImg"
  99. />
  100. </div>
  101. <el-pagination
  102. v-if="userList.length > 0"
  103. background
  104. :page-size="8"
  105. layout="prev, pager, next"
  106. :current-page="page"
  107. :total="totalNum"
  108. @current-change="changePage"
  109. ></el-pagination>
  110. <!-- 重置密码 -->
  111. <el-dialog
  112. title="重置密码"
  113. :visible.sync="resetPassDialogVisible"
  114. width="30%"
  115. @close="resetPassDialogClosed"
  116. >
  117. <el-form
  118. ref="resetPassFormRef"
  119. :model="resetPassForm"
  120. label-width="110px"
  121. :rules="resetPassFormRules"
  122. >
  123. <el-form-item label="用户名 : " prop="username">
  124. <el-input
  125. type="text"
  126. disabled
  127. v-model="resetPassForm.username"
  128. ></el-input>
  129. </el-form-item>
  130. <el-form-item v-if="userType != 1" label="原始密码 : " prop="oldPass">
  131. <el-input type="password" v-model="resetPassForm.oldPass"></el-input>
  132. </el-form-item>
  133. <el-form-item label="新密码 : " prop="pass">
  134. <el-input type="password" v-model="resetPassForm.pass"></el-input>
  135. </el-form-item>
  136. <el-form-item label="确认新密码 : " prop="checkPass">
  137. <el-input
  138. type="password"
  139. v-model="resetPassForm.checkPass"
  140. ></el-input>
  141. </el-form-item>
  142. </el-form>
  143. <span slot="footer" class="dialog-footer">
  144. <el-button @click="resetPassDialogVisible = false">取 消</el-button>
  145. <el-button type="primary" @click="resetPassSubm">确认</el-button>
  146. </span>
  147. </el-dialog>
  148. <!-- 用户编辑 -->
  149. <el-dialog
  150. title="用户信息编辑"
  151. :visible.sync="editUserDialogVisible"
  152. width="500px"
  153. @close="editUserDialogClosed"
  154. >
  155. <el-form ref="editUserFormRef" :model="editUserForm" label-width="80px">
  156. <el-form-item label="用户名 : ">
  157. <el-input v-model="editUserForm.username" disabled></el-input>
  158. </el-form-item>
  159. <el-form-item label="标题 : ">
  160. <el-input
  161. maxlength="11"
  162. v-model="editUserForm.user_header"
  163. ></el-input>
  164. </el-form-item>
  165. <el-form-item label="logo : ">
  166. <el-upload
  167. class="avatar-uploader"
  168. action
  169. :auto-upload="false"
  170. :show-file-list="false"
  171. :on-change="changeUpload"
  172. :before-upload="beforeAvatarUpload"
  173. >
  174. <img
  175. v-if="editUserForm.logo"
  176. :src="editUserForm.logo"
  177. class="avatar"
  178. />
  179. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  180. </el-upload>
  181. </el-form-item>
  182. <el-form-item label="站点名称 : ">
  183. <el-input maxlength="16" v-model="editUserForm.site"></el-input>
  184. </el-form-item>
  185. <el-form-item label="站点位置 : ">
  186. <div class="block">
  187. <el-cascader
  188. placeholder="搜索:河南"
  189. v-model="cityValue"
  190. :options="cityData"
  191. :props="props"
  192. @change="handleChange"
  193. filterable
  194. >
  195. </el-cascader>
  196. </div>
  197. </el-form-item>
  198. </el-form>
  199. <span slot="footer" class="dialog-footer">
  200. <el-button @click="editUserDialogVisible = false">取 消</el-button>
  201. <el-button type="primary" @click="editUserSubm">确认</el-button>
  202. </span>
  203. </el-dialog>
  204. </div>
  205. </template>
  206. <script>
  207. import cityData from "./citydata.js";
  208. export default {
  209. data() {
  210. var checkMobile = (rule, value, callback) => {
  211. const regMobile = /^1\d{10}$/;
  212. if (regMobile.test(value)) {
  213. callback();
  214. } else {
  215. // 返回一个错误提示
  216. callback(new Error("请输入合法的手机号码"));
  217. }
  218. };
  219. var validatePass = (rule, value, callback) => {
  220. if (value === "") {
  221. callback(new Error("请输入新密码"));
  222. } else {
  223. if (this.resetPassForm.checkPass !== "") {
  224. this.$refs.resetPassFormRef.validateField("checkPass");
  225. }
  226. callback();
  227. }
  228. };
  229. var validatePass2 = (rule, value, callback) => {
  230. if (value === "") {
  231. callback(new Error("请再次输入密码"));
  232. } else if (value !== this.resetPassForm.pass) {
  233. callback(new Error("两次输入密码不一致!"));
  234. } else {
  235. callback();
  236. }
  237. };
  238. return {
  239. zanwu: "/images/expertDiagnosis/zanwu.png",
  240. role: "", //筛选项 角色类型
  241. userTypeCheck: "", //筛选项 用户类型
  242. username: "", //筛选项
  243. roleList: [],
  244. page: 1,
  245. userList: [],
  246. userGroupList: [],
  247. totalNum: 0,
  248. //省市县
  249. areaList: [],
  250. resetPassDialogVisible: false,
  251. addUserDialogVisible: false,
  252. editUserDialogVisible: false,
  253. resetPassForm: {
  254. username: "",
  255. uid: "",
  256. oldPass: "",
  257. pass: "",
  258. checkPass: "",
  259. },
  260. addUserForm: {
  261. username: "",
  262. mobile: "",
  263. pass: "",
  264. role_id: "",
  265. user_type: "",
  266. pcd: "",
  267. user_area: "",
  268. cs_user: false, //1为普通用户
  269. user_group_id: "", //用户组id
  270. },
  271. cityData,
  272. cityValue: [],
  273. props: {
  274. expandTrigger: "hover",
  275. value: "value",
  276. },
  277. editUserForm: {},
  278. //控制省/市/区显示
  279. editIsShow: false,
  280. //添加用户规则
  281. addUserFormRules: {
  282. username: [
  283. { required: true, message: "请填写用户名", trigger: "blur" },
  284. ],
  285. mobile: [
  286. { required: true, trigger: "blur", message: "手机号不能为空" },
  287. { validator: checkMobile, trigger: "blur" },
  288. ],
  289. pass: [{ required: true, message: "请填写用户密码", trigger: "blur" }],
  290. },
  291. //重置密码格规则
  292. resetPassFormRules: {
  293. oldPass: [{ required: true, message: "请填原始密码", trigger: "blur" }],
  294. pass: [
  295. { validator: validatePass, trigger: "blur" },
  296. { required: true, message: "请填写新密码", trigger: "blur" },
  297. ],
  298. checkPass: [
  299. { validator: validatePass2, trigger: "blur" },
  300. { required: true, message: "请确认新密码", trigger: "blur" },
  301. ],
  302. },
  303. have_type: "",
  304. staff: "",
  305. };
  306. },
  307. computed: {
  308. //获取用户类型
  309. userType: function () {
  310. return window.sessionStorage.getItem("myuser_type");
  311. },
  312. },
  313. created() {},
  314. mounted() {
  315. this.getList();
  316. this.have_type = localStorage.getItem("have_type"); // 0管理员 1用户
  317. this.staff = localStorage.getItem("staff"); // 1是admin
  318. },
  319. methods: {
  320. getList() {
  321. this.$axios({
  322. method: "POST",
  323. url: "user_list",
  324. data: this.qs.stringify({
  325. typelist: 5,
  326. page: this.page,
  327. uname: this.username,
  328. }),
  329. }).then((res) => {
  330. this.userList = res.data.userlist;
  331. this.totalNum = res.data.nums;
  332. });
  333. },
  334. getUserGroup() {
  335. this.$axios({
  336. method: "POST",
  337. url: "api_gateway?method=pest.warning_record.rolemanage_view",
  338. data: this.qs.stringify({
  339. add_role: "all",
  340. }),
  341. }).then((res) => {
  342. if (res.data.message == "") {
  343. this.userGroupList = res.data.data.data;
  344. }
  345. });
  346. },
  347. recharge(id) {
  348. this.$confirm("是否向该用户充值一年费用?", "信息", {
  349. confirmButtonText: "确定",
  350. cancelButtonText: "取消",
  351. type: "warning",
  352. })
  353. .then(() => {
  354. this.$axios({
  355. method: "POST",
  356. url: "api_gateway?method=user.login.user_add_package_time",
  357. data: this.qs.stringify({
  358. uid: id,
  359. }),
  360. }).then((res) => {
  361. if (res.data.message == "") {
  362. this.$message({
  363. type: "success",
  364. message: "充值成功!",
  365. });
  366. this.getList();
  367. } else {
  368. this.$message({
  369. type: "error",
  370. message: "充值失败!",
  371. });
  372. }
  373. });
  374. })
  375. .catch(() => {
  376. this.$message({
  377. type: "info",
  378. message: "充值取消!",
  379. });
  380. });
  381. },
  382. // 编辑用户信息
  383. edit(role) {
  384. this.editUserForm = JSON.parse(JSON.stringify(role));
  385. this.editUserDialogVisible = true;
  386. this.cityValue = [
  387. this.editUserForm.user_pro,
  388. this.editUserForm.user_city,
  389. this.editUserForm.user_area,
  390. ];
  391. },
  392. beforeAvatarUpload(file) {
  393. console.log(file);
  394. const isJPG = file.type === "image/jpeg" || file.type === "image/png";
  395. const isLt2M = file.size / 1024 / 1024 < 2;
  396. if (!isJPG) {
  397. this.$message.error("上传头像图片只能是 JPG 和 PNG格式!");
  398. }
  399. if (!isLt2M) {
  400. this.$message.error("上传头像图片大小不能超过 2MB!");
  401. }
  402. return isJPG && isLt2M;
  403. },
  404. changeUpload(file, fileList) {
  405. var form = new FormData();
  406. form.append("img_file", file.raw);
  407. this.$axios({
  408. method: "POST",
  409. url: "base_photo",
  410. data: form,
  411. }).then((res) => {
  412. this.editUserForm.logo = res.data.src;
  413. });
  414. },
  415. handleChange(value) {
  416. console.log(value);
  417. console.log(this.cityValue);
  418. this.editUserForm.user_pro = value[0];
  419. this.editUserForm.user_city = value[1];
  420. if (value[2]) {
  421. this.editUserForm.user_area = value[2];
  422. } else {
  423. this.editUserForm.user_city = value[0].substring(
  424. 0,
  425. value[0].length - 1
  426. );
  427. this.editUserForm.user_area = value[1];
  428. }
  429. },
  430. login(uid, username) {
  431. //一键登录
  432. this.$confirm("一键登录将登录此用户,是否继续?", "提示", {
  433. confirmButtonText: "确定",
  434. cancelButtonText: "取消",
  435. type: "warning",
  436. })
  437. .then(() => {
  438. this.$axios({
  439. method: "POST",
  440. url: "api_gateway?method=user.login.auto_login",
  441. data: this.qs.stringify({
  442. uid,
  443. }),
  444. }).then((res) => {
  445. if (res.data.message == "") {
  446. this.$message({
  447. type: "success",
  448. message: "操作成功!",
  449. });
  450. localStorage.setItem("username", username); //修改当前登录的用户名
  451. this.reload(); //整体刷新
  452. this.$EventBus.$on("firstPage", (data) => {
  453. //默认显示菜单第一项
  454. this.$router.push(`${data}`);
  455. });
  456. } else {
  457. this.$message({
  458. type: "warning",
  459. message: res.data.message,
  460. });
  461. }
  462. });
  463. })
  464. .catch(() => {
  465. this.$message({
  466. type: "info",
  467. message: "取消一键登录!",
  468. });
  469. });
  470. },
  471. //用户禁用
  472. forbidUse(id, state, txt) {
  473. this.$confirm(txt, "提示", {
  474. confirmButtonText: "确定",
  475. cancelButtonText: "取消",
  476. type: "warning",
  477. })
  478. .then(() => {
  479. this.$axios({
  480. method: "POST",
  481. url: "api_gateway?method=user.login.users_statu_updata",
  482. data: this.qs.stringify({
  483. uid: id,
  484. state: state,
  485. }),
  486. }).then((res) => {
  487. if (res.data.message == "") {
  488. this.$message({
  489. type: "success",
  490. message: "操作成功!",
  491. });
  492. this.getList();
  493. }
  494. });
  495. })
  496. .catch(() => {
  497. this.$message({
  498. type: "info",
  499. message: "禁用取消!",
  500. });
  501. });
  502. },
  503. //密码重置
  504. resetPassword(id, name) {
  505. this.resetPassForm.id = id;
  506. this.resetPassForm.username = name;
  507. this.resetPassDialogVisible = true;
  508. },
  509. resetPassSubm() {
  510. //暂时不用
  511. this.$refs.resetPassFormRef.validate((valid) => {
  512. if (!valid) return;
  513. this.$axios({
  514. method: "POST",
  515. url: "systemmanage_user_list",
  516. data: this.qs.stringify({
  517. id: this.resetPassForm.id,
  518. req: "resetpwd",
  519. userName: this.editUserForm.username,
  520. userpassWord: this.resetPassForm.pass,
  521. userRePassWord: this.resetPassForm.pass,
  522. }),
  523. }).then((res) => {
  524. if (res.data == 0) {
  525. this.$message.success("修改密码成功");
  526. this.resetPassDialogVisible = false;
  527. } else {
  528. this.$message.error(res.data.message);
  529. }
  530. });
  531. });
  532. },
  533. //监听重置密码对话框的关闭事件
  534. resetPassDialogClosed() {
  535. this.$refs.resetPassFormRef.resetFields();
  536. },
  537. changePage(value) {
  538. this.page = value;
  539. this.getList();
  540. },
  541. //添加用户
  542. addUser() {
  543. this.addUserDialogVisible = true;
  544. },
  545. //监听用户类型改变
  546. userTypeChange(val) {
  547. if (val == 3) {
  548. this.editIsShow = true;
  549. } else {
  550. this.editIsShow = false;
  551. }
  552. },
  553. //监听省/市/区
  554. pcdChange(val) {
  555. let addr_type = "";
  556. switch (val) {
  557. case "1":
  558. addr_type = "province";
  559. break;
  560. case "2":
  561. addr_type = "city";
  562. break;
  563. case "3":
  564. addr_type = "district";
  565. break;
  566. }
  567. this.$axios({
  568. method: "POST",
  569. url: "api_gateway?method=device.device_manage.device_addr",
  570. data: this.qs.stringify({
  571. addr_type,
  572. }),
  573. }).then((res) => {
  574. if (res.data.message == "") {
  575. this.areaList = res.data.data;
  576. this.editUserForm.user_area = "";
  577. }
  578. });
  579. },
  580. //添加用户提交
  581. addUserSubm() {
  582. this.$refs.addUserFormRef.validate((valid) => {
  583. if (!valid) return;
  584. let cs_user = this.addUserForm.cs_user ? "1" : "";
  585. this.$axios({
  586. method: "POST",
  587. url: "api_gateway?method=user.login.regiest",
  588. data: this.qs.stringify({
  589. username: this.addUserForm.username,
  590. mobile: this.addUserForm.mobile,
  591. password: this.addUserForm.pass,
  592. role_id: this.addUserForm.role_id,
  593. user_type: this.addUserForm.user_type,
  594. pcd: this.addUserForm.pcd,
  595. user_area: this.addUserForm.user_area,
  596. user_group_id: this.addUserForm.user_group_id,
  597. cs_user,
  598. }),
  599. }).then((res) => {
  600. if (res.data.message == "") {
  601. this.$message.success("添加用户成功!");
  602. this.addUserDialogVisible = false;
  603. this.getList();
  604. } else {
  605. this.$message.error(res.data.message);
  606. }
  607. });
  608. });
  609. },
  610. addUserDialogClosed() {
  611. this.$refs.addUserFormRef.resetFields();
  612. },
  613. //修改用户信息提交
  614. editUserSubm() {
  615. this.$refs.editUserFormRef.validate((valid) => {
  616. if (!valid) return;
  617. this.$axios({
  618. method: "POST",
  619. url: "user_detail",
  620. data: this.qs.stringify(this.editUserForm),
  621. }).then((res) => {
  622. if (res.data == 1) {
  623. this.editUserDialogVisible = false;
  624. var curr = localStorage.getItem("username");
  625. if (curr == this.editUserForm.username) {
  626. window.location.reload();
  627. } else {
  628. this.getList();
  629. }
  630. }
  631. });
  632. });
  633. },
  634. editUserDialogClosed() {
  635. this.$refs.editUserFormRef.resetFields();
  636. this.areaList = []; //清空省/市/区
  637. this.editIsShow = false;
  638. },
  639. checkList() {
  640. this.page = 1;
  641. this.getList();
  642. },
  643. },
  644. filters: {
  645. formatUserType(value) {
  646. switch (value) {
  647. case 1:
  648. return "超级管理员";
  649. break;
  650. case 2:
  651. return "经销商";
  652. break;
  653. case 3:
  654. return "农林政府单位";
  655. break;
  656. case 4:
  657. return "普通用户";
  658. break;
  659. }
  660. },
  661. },
  662. };
  663. </script>
  664. <style lang='less' scoped>
  665. .search-box {
  666. display: flex;
  667. justify-content: space-between;
  668. margin-bottom: 10px;
  669. .filter-box > div {
  670. margin-right: 15px;
  671. }
  672. .el-input {
  673. width: 200px;
  674. }
  675. .el-date-editor--daterange {
  676. width: 222px;
  677. }
  678. }
  679. .el-card {
  680. .img-box {
  681. text-align: center;
  682. border-bottom: 1px solid #e1e1e1;
  683. padding: 15px 0;
  684. p {
  685. font-size: 14px;
  686. font-weight: 800;
  687. margin-top: 10px;
  688. }
  689. }
  690. .detail {
  691. border-bottom: 1px solid #e1e1e1;
  692. padding: 10px 0;
  693. padding: 0 20px;
  694. p {
  695. display: flex;
  696. justify-content: space-between;
  697. font-size: 13px;
  698. line-height: 34px;
  699. color: #666;
  700. padding: 0 0px;
  701. }
  702. }
  703. .btn {
  704. text-align: center;
  705. padding: 20px 10px;
  706. display: flex;
  707. justify-content: space-around;
  708. button {
  709. // flex: 1;
  710. margin: 0 8px;
  711. border: 1px solid #17bb89;
  712. color: #17bb89;
  713. // border-radius: 4px;
  714. // font-size: 12px;
  715. // padding: 5px 5px;
  716. background: #fff;
  717. cursor: pointer;
  718. i {
  719. font-size: 12px;
  720. margin-right: 2px;
  721. }
  722. }
  723. button:hover {
  724. background: #fff;
  725. border: 1px solid #47d9ad;
  726. color: #47d9ad;
  727. }
  728. }
  729. }
  730. // 暂无数据
  731. .expertDiagnosis_referral_units_not {
  732. width: 272px;
  733. margin: 0 auto;
  734. }
  735. </style>