password.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <template>
  2. <view class="page">
  3. <headerline shownav=true isback="true" @tapnav="tapnav" :navstyle="navstyle" :navitem="navitem" :navselect="navselect" :statusbarheight='statusBarHeight' ></headerline>
  4. <view v-if="navselect==0">
  5. <ul class="profile" v-if="!isfrist" >
  6. <li>原始密码:</li>
  7. <li>
  8. <input type="password" id="password" v-model="pwd0" style="width: 150px;" class="input1" placeholder="请输入原始登录密码" />
  9. </li>
  10. </ul>
  11. <ul class="profile" >
  12. <li>新登录密码:</li>
  13. <li>
  14. <input type="password" id="password" v-model="pwd1" style="width: 150px;" class="input1" placeholder="请输入新登录密码" />
  15. </li>
  16. </ul>
  17. <ul class="profile" >
  18. <li>确认登录密码:</li>
  19. <li>
  20. <input type="password" id="password" v-model="pwd2" style="width: 150px;" class="input1" placeholder="再次输入新登录密码" oninput="checkpwd(this.value);" onblur="check_other(this.value,'password');check_other($('#password2').val(),'password1');" />
  21. </li>
  22. </ul>
  23. <view style="margin:15px auto;display:block;width: 80%;">
  24. <button class="button1" @tap="change_pwd()">确认修改</button>
  25. </view>
  26. </view>
  27. <view v-else>
  28. <ul class="profile" >
  29. <li>手机号:</li>
  30. <li>
  31. {{mobileshow}}
  32. </li>
  33. </ul>
  34. <ul class="profile" >
  35. <li>验证码:</li>
  36. <li><input type="text" class="input1" id="randcode" v-model="randcode" placeholder="短信验证码" maxlength="6"
  37. style="width:80px;height:30px;line-height: 30px;display: inline-block;vertical-align: middle;" />
  38. <span class="sendbtn" @tap="sendsms()" style="display: inline-block;margin-left: 5px;" v-if='!disabled'>发送短信</span>
  39. <span class="sendbtn" style="display: inline-block;margin-left: 5px;" v-else>
  40. <block v-if="issending">发送中...</block>
  41. <block v-else>
  42. {{getCodeTime}}秒后再获取
  43. </block>
  44. </span>
  45. </li>
  46. </ul>
  47. <ul class="profile" >
  48. <li>新登录密码:</li>
  49. <li><input type="password" class="input1" id="pwd" v-model="pwd" placeholder="输入新的登录密码" />
  50. </li>
  51. </ul>
  52. <view style="margin:15px auto;display:block;width: 80%;">
  53. <button class="button1" @tap="reset_pwd()">
  54. 确认并提交
  55. </button>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import api from "../../library/index.js"
  62. import headerline from '../../components/header.vue'
  63. import http from "../../library/http.js"
  64. import uniIcons from '../../components/uni-icons/uni-icons.vue'
  65. var statusBarHeight = uni.getSystemInfoSync().statusBarHeight ;
  66. export default {
  67. components: {
  68. uniIcons,
  69. headerline,
  70. },
  71. data() {
  72. return {
  73. statusBarHeight: statusBarHeight+ 'px',
  74. navitem:['修改登录密码','忘记登录密码'],
  75. navselect:0,
  76. navstyle:"width:60%;left:20%",
  77. user: uni.getStorageSync('userInfo'),
  78. system: uni.getStorageSync('system'),
  79. isfrist:false,
  80. pwd0:'',
  81. pwd1:'',
  82. pwd2:'',
  83. pwd:'',
  84. step:1,
  85. mobile:'',
  86. mobileshow:'',
  87. type:'pwd',
  88. timer:null,
  89. getCodeTime:60,
  90. disabled:false,
  91. issending:false,
  92. randcode:'',
  93. }
  94. },
  95. methods: {
  96. tapnav(num){
  97. if(num==1 && this.user.mobile==''){
  98. uni.showModal({
  99. title: '提示',
  100. content: "绑定手机号,才可以重置密码",
  101. showCancel: true,
  102. cancelText: '关闭',
  103. confirmText: '绑定手机号',
  104. success: res => {
  105. if(res.confirm) {
  106. uni.redirectTo({
  107. url:"/pages/mine/mobile"
  108. })
  109. }
  110. }
  111. });
  112. }
  113. else{
  114. this.navselect=num;
  115. if(num==1){
  116. this.setuserdata();
  117. this.getuserinfo();
  118. }
  119. }
  120. },
  121. change_pwd() {
  122. if(!this.isfrist && this.pwd0==''){
  123. uni.showToast({
  124. icon:'none',
  125. title:'请输入原始登录密码',
  126. duration:1000
  127. })
  128. return false;
  129. }
  130. if(this.pwd1==''){
  131. uni.showToast({
  132. icon:'none',
  133. title:'请输入新登录密码',
  134. duration:1000
  135. })
  136. return false;
  137. }
  138. if(this.pwd1.length<6){
  139. uni.showToast({
  140. icon:'none',
  141. title:'新密码长度不能小于',
  142. duration:1000
  143. })
  144. return false;
  145. }
  146. if(this.pwd1!=this.pwd2){
  147. uni.showToast({
  148. icon:'none',
  149. title:'两次密码输入不一致',
  150. duration:1000
  151. })
  152. return false;
  153. }
  154. http.setWait(true).post('user.php?act=change_pwd',{method:'login',id:this.user.id,password:this.pwd1,oldpwd:this.pwd0,isfrist:this.isfrist}).then(res=>{
  155. this.pwd0=this.pwd1=this.pwd2='';
  156. uni.showToast({
  157. icon:'none',
  158. title:'登录密码已修改成功',
  159. duration:1000
  160. })
  161. })
  162. },
  163. sendsms() {
  164. var mobile=this.mobile;
  165. var reg =/^0?1[3|4|5|6|7|8|9][0-9]\d{8}$/;
  166. if(reg.test(mobile)){
  167. this.disabled=true;
  168. this.issending=true;
  169. http.setWait(true).post('user.php?act=sendCode',{mobile:mobile,type:this.type}).then(res=>{
  170. this.issending=false;
  171. if(res.data.method!='error'){
  172. var that=this;
  173. clearInterval(that.timer);
  174. that.timer=setInterval(function () {
  175. that.getCodeTime--;
  176. that.disabled=true;
  177. if(that.getCodeTime<=0){
  178. that.disabled=false;
  179. that.getCodeTime=60;
  180. clearInterval(that.timer);
  181. }
  182. },1000)
  183. }else{
  184. var that=this;
  185. that.disabled=false;
  186. that.getCodeTime=60;
  187. clearInterval(that.timer);
  188. uni.showToast({
  189. icon:'none',
  190. title:'短信发送失败',
  191. duration:1000
  192. })
  193. }
  194. })
  195. }else{
  196. uni.showToast({
  197. icon:'none',
  198. title:'手机号码格式错误',
  199. duration:1000
  200. })
  201. return false;
  202. }
  203. },
  204. setuserdata(){
  205. if(this.user.mobile){
  206. this.mobile=this.user.mobile;
  207. this.mobileshow=this.mobile.substr(0,3)+"*****"+this.mobile.substr(this.mobile.length-3,3);
  208. }
  209. },
  210. getuserinfo(){
  211. var postdata={
  212. id: uni.getStorageSync('access_token')
  213. };
  214. http.setWait(false).post('user.php?act=userinfo',postdata).then(res=>{
  215. this.user=res.data;
  216. uni.setStorageSync('userInfo',this.user)
  217. this.setuserdata();
  218. })
  219. },
  220. reset_pwd() {
  221. var mobile=this.mobile;
  222. if(mobile==''){
  223. uni.showToast({
  224. icon:'none',
  225. title:'手机号不能为空',
  226. duration:1000
  227. })
  228. return false;
  229. }
  230. var reg =/^0?1[3|4|5|6|7|8|9][0-9]\d{8}$/;
  231. if(!reg.test(mobile)){
  232. uni.showToast({
  233. icon:'none',
  234. title:'手机号码格式错误',
  235. duration:1000
  236. })
  237. return false;
  238. }
  239. if(this.randcode==''){
  240. uni.showToast({
  241. icon:'none',
  242. title:'短信验证码不能为空',
  243. duration:1000
  244. })
  245. return false;
  246. }
  247. if(this.pwd==''){
  248. uni.showToast({
  249. icon:'none',
  250. title:'请输入新登录密码',
  251. duration:1000
  252. })
  253. return false;
  254. }
  255. if(this.pwd.length<6){
  256. uni.showToast({
  257. icon:'none',
  258. title:'新密码长度不能小于6',
  259. duration:1000
  260. })
  261. return false;
  262. }
  263. http.setWait(true).post('user.php?act=reset_pwd',{id:this.user.id,mobile:mobile,randcode:this.randcode,pwd:this.pwd,method:'login'}).then(res=>{
  264. this.pwd=this.randcode='';
  265. uni.showToast({
  266. icon:'none',
  267. title:'登录密码已重置成功',
  268. duration:1000
  269. })
  270. })
  271. }
  272. },
  273. onLoad(opts) {
  274. var pwd=this.user.pwd;
  275. if(pwd==undefined || pwd==null || pwd=='' ){
  276. this.isfrist=true;
  277. }
  278. else {
  279. this.isfrist=false;
  280. }
  281. }
  282. }
  283. </script>
  284. <style lang="scss" scoped>
  285. @import "@/static/css/user.css";
  286. .page{
  287. background-color: #fafafa;
  288. }
  289. .profile,.login-lines1{
  290. background-color: #fff;
  291. margin: 10px auto;
  292. width: 100%;
  293. vertical-align: middle;
  294. }
  295. .profile li{
  296. vertical-align: middle;
  297. }
  298. .profile li:first-child{
  299. width:120px
  300. }
  301. .profile li:last-child{
  302. width:calc(100% - 130px)
  303. }
  304. </style>