Pwd.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <div class="pages">
  3. <div class="image-border image-border1"></div>
  4. <div class="image-border image-border2"></div>
  5. <div class="image-border image-border3"></div>
  6. <div class="image-border image-border4"></div>
  7. <div class="tabs">
  8. <ul>
  9. <li v-for="(tab,i) in tabs" @click="goTab(tab.url)" :class="{'active':tabIndex == i}">
  10. {{tab.name}}
  11. </li>
  12. </ul>
  13. </div>
  14. <div class="form_container">
  15. <el-form ref="form" :model="form" label-width="110px" :rules="rules">
  16. <el-form-item label="请输入原密码" prop="old">
  17. <el-input v-model="form.old" type="password"></el-input>
  18. </el-form-item>
  19. <el-form-item label="新密码" prop="newpwd">
  20. <el-input v-model="form.newpwd" type="password"></el-input>
  21. </el-form-item>
  22. <el-form-item label="确认密码" prop="again">
  23. <el-input v-model="form.again" type="password"></el-input>
  24. </el-form-item>
  25. <el-form-item label="图形验证码" prop="valid">
  26. <el-input v-model="form.valid" type="password"></el-input>
  27. <img id="validImg" :src="valImgSrc" alt="" width="100px" height="30px" title="看不清?刷一下试试!" @click="changeValImg" >
  28. </el-form-item>
  29. <!--<s>-->
  30. <!--<i class="el-icon-warning"></i><em>密码由6~32位字母、数字及下划线组成</em>-->
  31. <!--</s>-->
  32. <el-form-item>
  33. <el-button size="small" type="primary" @click="onSubmit('form')">确认</el-button>
  34. <!--<el-button size="small" type="primary" @click="resetForm('form')">重置</el-button>-->
  35. </el-form-item>
  36. </el-form>
  37. </div>
  38. </div>
  39. </template>
  40. <script>
  41. let qs = require('qs');
  42. import Global from '../Global.js'
  43. import {modPwd, logout} from '../api/getApiRes.js'
  44. import {GenVerifyPic } from '../api/getApiRes.js'
  45. export default {
  46. data() {
  47. let samepass = (rule, value, callback) => {
  48. if (value !== this.form.newpwd) {
  49. callback(new Error('两次输入密码不一致!'));
  50. } else {
  51. callback();
  52. }
  53. };
  54. let pwdPass = (rule, value, callback) => {
  55. let re = /^[0-9a-zA-Z_]{1,}$/;
  56. if (value.search(re) == -1) {
  57. callback(new Error('错了哦,密码只能由字母、数字及下划线组成'));
  58. } else {
  59. callback()
  60. }
  61. };
  62. return {
  63. tabIndex: 2,
  64. tabs: [
  65. {name: '固件管理', url: 'hardware'},
  66. {name: '警务通管理', url: 'police'},
  67. {name: '密码修改', url: 'pwd'},
  68. {name: '系统设置', url: 'setting'},
  69. ],
  70. valImgSrc: '',
  71. overtime: '',
  72. form: {
  73. old: '',
  74. newpwd: '',
  75. again: '',
  76. valid: '',
  77. },
  78. rules: {
  79. old: [
  80. {required: true, message: '请输入原密码', trigger: 'blur'},
  81. {min: 6, max: 32, message: '长度在 6 到 32 个字符', trigger: 'blur'}
  82. ],
  83. newpwd: [
  84. {required: true, message: '请输入新密码', trigger: 'blur'},
  85. {min: 6, max: 32, message: '长度在 6 到 32 个字符', trigger: 'blur'},
  86. {validator: pwdPass, trigger: 'blur'}
  87. ],
  88. again: [
  89. {required: true, message: '请输入确认密码', trigger: 'blur'},
  90. {min: 6, max: 32, message: '长度在 6 到 32 个字符', trigger: 'blur'},
  91. {validator: pwdPass, trigger: 'blur'},
  92. {validator: samepass, trigger: 'blur'},
  93. ],
  94. valid: [
  95. {required: true, message: '请输入图形验证码', trigger: 'blur'},
  96. {min: 3, max: 4, message: '长度在 4 个字符', trigger: 'blur'}
  97. ],
  98. }
  99. }
  100. },
  101. mounted() {
  102. // 读取验证码
  103. this.CurentGenVerifyPic();
  104. this.overtime = new Date();
  105. },
  106. methods: {
  107. // 跳转tab页面
  108. goTab(url) {
  109. this.$router.push({path: url});
  110. },
  111. CurentGenVerifyPic(){
  112. let that = this;
  113. let postdata;
  114. GenVerifyPic(postdata).then(res => {
  115. let json = res;
  116. if (json.Id) {
  117. that.valImgSrc=json.Pic;
  118. that.form.picId=json.Id;
  119. this.validImgState = false;
  120. } else {
  121. that.$message.error(json.Memo);
  122. }
  123. })
  124. },
  125. // 点击验证码切换
  126. changeValImg: function () {
  127. this.validImgState = true;
  128. this.CurentGenVerifyPic();
  129. },
  130. onSubmit(formName) {
  131. let that = this;
  132. this.$refs[formName].validate((valid) => {
  133. if (valid) {
  134. that.submitPwd()
  135. } else {
  136. that.$message({
  137. showClose: true,
  138. message: '错了哦,提交新密码失败',
  139. type: 'error'
  140. });
  141. that.form.old = '';
  142. that.form.newpwd = '';
  143. that.form.again = '';
  144. return false;
  145. }
  146. });
  147. },
  148. resetForm(formName) {
  149. this.$refs[formName].resetFields();
  150. },
  151. submitPwd() {
  152. let that = this;
  153. let param = {
  154. oldPwd: that.form.old,
  155. newPwd: that.form.newpwd,
  156. };
  157. let postdata = qs.stringify(param);
  158. modPwd(postdata).then(res => {
  159. let json = res;
  160. if (json.Code == 0) {
  161. that.$message({
  162. showClose: true,
  163. message: '密码修改成功',
  164. type: 'success'
  165. });
  166. // clean info
  167. that.old = '';
  168. that.newpwd = '';
  169. that.again = '';
  170. that.logoutPage();
  171. } else {
  172. that.$message.error(json.Memo);
  173. }
  174. });
  175. },
  176. // 重登录
  177. logoutPage() {
  178. const that = this;
  179. let postdata = {};
  180. logout(postdata).then(res => {
  181. let json = res;
  182. if (json.Code == 0) {
  183. that.$router.push({
  184. path: '/login',
  185. query: {
  186. status: 1
  187. }
  188. })
  189. } else {
  190. that.$message.error(json.Memo);
  191. }
  192. })
  193. }
  194. },
  195. }
  196. </script>
  197. <style scoped>
  198. @import "../assets/css/panel.css";
  199. .tabs ul {
  200. width: 800px;
  201. }
  202. .image-border {
  203. position: absolute;
  204. width: 20px;
  205. height: 20px;
  206. }
  207. .image-border1 {
  208. top: 0;
  209. left: 25px;
  210. border-left: 2px solid #6DC1FF;
  211. border-top: 2px solid #6DC1FF;
  212. }
  213. .image-border2 {
  214. top: 0;
  215. right: 12px;
  216. border-right: 2px solid #6DC1FF;
  217. border-top: 2px solid #6DC1FF;
  218. }
  219. .image-border3 {
  220. bottom: 0;
  221. left: 25px;
  222. border-bottom: 2px solid #6DC1FF;
  223. border-left: 2px solid #6DC1FF;
  224. }
  225. .image-border4 {
  226. bottom: 0;
  227. right: 12px;
  228. border-right: 2px solid #6DC1FF;
  229. border-bottom: 2px solid #6DC1FF;
  230. }
  231. .pages {
  232. /*position: absolute;*/
  233. /*top: 0;*/
  234. /*bottom: 0;*/
  235. /*left: 0;*/
  236. /*right: 0;*/
  237. width: 100%;
  238. /*height: 100%;*/
  239. min-height: 600px;
  240. overflow: hidden;
  241. display: block;
  242. margin: 0 auto;
  243. padding-bottom: 80px;
  244. }
  245. .form_container {
  246. width: 50%;
  247. overflow: hidden;
  248. margin: 0 auto;
  249. margin-top: 20px;
  250. padding: 20px;
  251. }
  252. s {
  253. height: 50px;
  254. line-height: 40px;
  255. padding-left: 20px;
  256. text-decoration: none;
  257. font-style: normal;
  258. }
  259. i {
  260. color: red;
  261. }
  262. s em {
  263. font-style: normal;
  264. }
  265. /deep/ .el-form {
  266. width: 500px;
  267. overflow: hidden;
  268. display: block;
  269. margin: 0 auto;
  270. }
  271. /deep/ .el-form-item__label {
  272. width: 120px!important;
  273. color: #6DC1FF;
  274. font-size: 16px;
  275. float: left;
  276. }
  277. /deep/ .el-form-item__content {
  278. width: 370px;
  279. float: right;
  280. overflow: hidden;
  281. margin-left: 0px!important;
  282. }
  283. /deep/ .el-input__inner {
  284. background: none;
  285. color: #6DC1FF;
  286. border: 1px solid #005EA2;
  287. border-radius: 0;
  288. }
  289. /deep/ .el-range-input {
  290. background: none;
  291. color: #6DC1FF;
  292. }
  293. .el-button--primary {
  294. width: 186px;
  295. height: 30px;
  296. background: #0162AA;
  297. color: #6DC1FF;
  298. border: 1px solid #6DC1FF;
  299. border-radius: 0;
  300. }
  301. #validImg {
  302. position: relative;
  303. float: right;
  304. bottom: 35px;
  305. }
  306. </style>