update_password.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <view>
  3. <hx-navbar :status-bar="true" :fixed="true" defaultBackUrl="security" left-text="设置密码">
  4. <view slot="right" class="navRight">
  5. <button class="nextBtn" size="mini" @click="formSubmit">完成</button>
  6. </view>
  7. </hx-navbar>
  8. <view class="content mRL">
  9. <view class="mt">
  10. <text class="text-gray ">
  11. 请设置{{appName}}密码,你可以用{{appName}}绑定的账号+{{appName}}密码登录,比如使用手机号+{{appName}}密码登录{{appName}},更快捷。
  12. </text>
  13. </view>
  14. <view class="pwsBox">
  15. <view class="listItem">
  16. <view class="listItem-left">
  17. 原密码
  18. </view>
  19. <view class="listItem-right" :class="[setActive1 && 'active']">
  20. <input type="text" :password="true" placeholder-style="color:#b5b5b5;" value=""
  21. :v-model="oldPwd"
  22. :focus="setActive1"
  23. placeholder="填写原密码"
  24. @focus="setActive1 = true"
  25. @blur="setActive1 = false"
  26. @input="setOldPwd"
  27. @confirm="formNext1"
  28. confirm-type="next"/>
  29. </view>
  30. </view>
  31. <view class="listItem">
  32. <view class="listItem-left">
  33. 新密码
  34. </view>
  35. <view class="listItem-right" :class="[setActive2 && 'active']">
  36. <input type="text" :password="true" placeholder-style="color:#b5b5b5;"
  37. value=""
  38. :focus="setActive2"
  39. placeholder="填写新密码"
  40. @focus="setActive2 = true"
  41. @blur="setActive2 = false"
  42. @input="setNewPwd"
  43. @confirm="formNext2"
  44. confirm-type="next"/>
  45. </view>
  46. </view>
  47. <view class="listItem">
  48. <view class="listItem-left">
  49. 确认密码
  50. </view>
  51. <view class="listItem-right" :class="[setActive3 && 'active']">
  52. <input type="text" :password="true" placeholder-style="color:#b5b5b5;" value=""
  53. placeholder="再次填写确认"
  54. :focus="setActive3"
  55. @focus="setActive3 = true"
  56. @blur="setActive3 = false"
  57. @input="setReNewPwd"
  58. @confirm="formNext3"
  59. confirm-type="done"/>
  60. </view>
  61. </view>
  62. </view>
  63. <view class="margin-top caption">
  64. 密码必须是8-16位的数字、字母组合(不能是纯数字)
  65. </view>
  66. <navigator url="forget_password" class="forget">
  67. 忘记原密码?
  68. </navigator>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. export default {
  74. data() {
  75. return {
  76. currentPhone: '',
  77. appName: this.$conf.appName,
  78. setActive1: true,
  79. setActive2: false,
  80. setActive3: false,
  81. oldPwd: '',
  82. newPwd: '',
  83. reNewPwd: '',
  84. }
  85. },
  86. methods: {
  87. setOldPwd(event){
  88. this.oldPwd = event.target.value;
  89. },
  90. setNewPwd(event){
  91. this.newPwd = event.target.value;
  92. },
  93. setReNewPwd(event){
  94. this.reNewPwd = event.target.value;
  95. },
  96. formNext1(value){
  97. this.oldPwd = value;
  98. setActive2 = true;
  99. },
  100. formNext2(value){
  101. this.newPwd = value;
  102. setActive3 = true;
  103. },
  104. formNext3(value){
  105. this.reNewPwd = value,
  106. this.formSubmit();
  107. },
  108. formSubmit(){
  109. let that = this;
  110. if(!this.oldPwd){
  111. uni.showModal({
  112. title: '提示',
  113. content: '请先填写原密码',
  114. confirmColor: '#3CC51F',
  115. showCancel: false,
  116. success: function (res) {
  117. if (res.confirm) {
  118. that.setActive1 = true
  119. }
  120. }
  121. });
  122. return;
  123. }
  124. if(that.oldPwd.length<6){
  125. uni.showToast({
  126. icon: 'none',
  127. position: 'bottom',
  128. title: '原密码不正确!'
  129. });
  130. return;
  131. }
  132. uni.showLoading({mask:true});
  133. //验证原密码
  134. that.$api.user.passwordValidation({
  135. 'str': that.$strEncode({
  136. oldPwd: that.oldPwd
  137. })
  138. }).then((res) => {
  139. let code = res.data.code;
  140. if(res.data.code != '0'){
  141. uni.showToast({
  142. icon: 'none',
  143. position: 'bottom',
  144. title: '原密码不正确!'
  145. });
  146. uni.hideLoading();
  147. that.setActive1 = true;
  148. return;
  149. }else{
  150. if(!this.newPwd || !this.reNewPwd || this.newPwd != this.reNewPwd){
  151. uni.showModal({
  152. title: '提示',
  153. content: '两次填写的密码不一致',
  154. confirmColor: '#3CC51F',
  155. showCancel: false,
  156. success: function (res) {
  157. if (res.confirm) {
  158. if(!that.newPwd){
  159. that.setActive2 = true
  160. }else{
  161. that.setActive3 = true
  162. }
  163. }
  164. }
  165. });
  166. uni.hideLoading();
  167. return;
  168. }
  169. var patrn=/^[0-9]{1,20}$/;
  170. if (patrn.exec(this.newPwd)){
  171. uni.showToast({
  172. icon: 'none',
  173. position: 'bottom',
  174. title: '密码不能为纯数字!'
  175. });
  176. return;
  177. }
  178. if(this.newPwd.length<8){
  179. uni.showToast({
  180. icon: 'none',
  181. position: 'bottom',
  182. title: '密码长度为8-20位!'
  183. });
  184. return;
  185. }
  186. //新密码不能和旧密码相同
  187. if(this.newPwd == this.oldPwd){
  188. uni.showModal({
  189. title: '提示',
  190. content: '新密码不能和原密码相同',
  191. confirmColor: '#3CC51F',
  192. showCancel: false,
  193. success: function (res) {
  194. if (res.confirm) {
  195. that.setActive1 = true
  196. }
  197. }
  198. });
  199. uni.hideLoading();
  200. return;
  201. }
  202. that.$api.user.updatePassword({
  203. 'str': that.$strEncode({
  204. oldPwd: that.oldPwd,
  205. newPwd: that.newPwd
  206. })
  207. }).then((res) => {
  208. uni.hideLoading();
  209. let code = res.data.code;
  210. if(code != '0'){
  211. uni.showToast({
  212. icon: 'none',
  213. position: 'bottom',
  214. title: res.data.msg
  215. });
  216. return;
  217. }
  218. uni.showToast({
  219. title: '完成',
  220. icon: 'success',
  221. duration: 2000,
  222. success:function (res){
  223. //修改成功后返回上一级
  224. setTimeout(function() {
  225. if(getCurrentPages().length>1){
  226. uni.navigateBack();
  227. }else{
  228. uni.redirectTo({
  229. url:'security'
  230. });
  231. }
  232. }, 2000);
  233. }
  234. });
  235. }).catch((err) =>{
  236. uni.hideLoading();
  237. })
  238. }
  239. }).catch((err)=>{
  240. uni.hideLoading();
  241. });
  242. },
  243. },
  244. }
  245. </script>
  246. <style lang="scss">
  247. .navRight{
  248. height: 100%;
  249. display: flex;
  250. justify-content: center;
  251. align-items: center;
  252. margin-right: 10upx;
  253. }
  254. .content{
  255. margin-left: 40upx;
  256. margin-right: 40upx;
  257. }
  258. .mt{
  259. margin-top: 56upx;
  260. }
  261. .pwsBox{
  262. display: flex;
  263. flex-direction:column;
  264. justify-content: center;
  265. margin-top: 40upx;
  266. }
  267. .listItem{
  268. display: flex;
  269. flex-direction:row;
  270. justify-content: center;
  271. align-items: flex-end;
  272. height: 90upx;
  273. }
  274. .listItem-left{
  275. margin-right: 20upx;
  276. width: 74px;
  277. padding-bottom: 14upx;
  278. padding-top: 12upx;
  279. font-size: 34upx;
  280. height: 72upx;
  281. }
  282. .listItem-right{
  283. border-bottom: 1upx solid #d6d6d6;
  284. padding: 12upx;
  285. font-size: 34upx;
  286. flex: 1;
  287. height: 72upx;
  288. }
  289. .listItem-right.active{
  290. border-bottom-color: $base-color;
  291. }
  292. .forget{
  293. color: #0077AA;
  294. font-size: 26upx;
  295. display: inline;
  296. }
  297. .caption{
  298. font-size: 26upx;
  299. color: #666666;
  300. margin-bottom: 8upx;
  301. }
  302. .nextBtn{
  303. background: $base-color;
  304. color: #ffffff;
  305. border-color: $base-color;
  306. }
  307. .nextBtn:after{
  308. border-color: $base-color;
  309. }
  310. </style>