Browse Source

修改密码

zs 2 years ago
parent
commit
64525cb54c
3 changed files with 149 additions and 6 deletions
  1. 75 4
      pagesMy/update/index.js
  2. 33 1
      pagesMy/update/index.wxml
  3. 41 1
      pagesMy/update/index.wxss

+ 75 - 4
pagesMy/update/index.js

@@ -1,20 +1,91 @@
 const app = getApp()
+import WxValidate from '../../utils/wxValidate'
+const moment = require("../../utils/moment.min");
 Page({
+
+    /**
+     * 页面的初始数据
+     */
     data: {
-        info: {}
+        form: {},
+    },
+    initValidate() {
+        const rules = { password: { required: true }, is_password: { required: true } }
+        const messages = { password: { required: '请输入新密码' }, is_password: { required: '请确认新密码' } };
+        this.WxValidate = new WxValidate(rules, messages)
     },
     /**
      * 生命周期函数--监听页面加载
      */
-    onLoad(options) {
+    async onLoad(options) {
         const that = this;
         wx.showLoading({ title: '加载中', mask: true })
+        //验证规则函数
+        that.initValidate();
         that.search()
         wx.hideLoading()
     },
-    // 查询通知
-    async search() {
+    search() {
+        const that = this;
+        wx.getStorage({
+            key: 'token',
+            async success(res) {
+                let form = {}
+                let aee = await app.$api(`user/${res.data._id}`, 'GET', {})
+                if (aee.errcode == '0') {
+                    form = aee.data;
+                } else {
+                    wx.showToast({ title: `${aee.errmsg}`, icon: 'error' });
+                }
+                that.setData({ form })
+            },
+            fail(err) {
+                console.log(err);
+            }
+        })
+    },
+    // 提交保存
+    async toSave(e) {
+        const that = this;
+        const params = e.detail.value;
+        if (!this.WxValidate.checkForm(params)) {
+            const error = that.WxValidate.errorList[0];
+            wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
+            return false
+        } else {
+            if (params.password !== params.is_password) {
+                wx.showToast({ title: '密码输入不一致', duration: 2000, icon: 'error', })
+            } else {
+                // 判断id使用
+                let form = that.data.form;
+                let data = { _id: form._id, password: params.password }
+                let res;
+                if (form._id) res = await app.$api(`user/rp`, 'POST', data);
+                else wx.showToast({ title: `未登录无法修改密码`, icon: 'none' });
+                if (res.errcode == '0') {
+                    wx.removeStorage({
+                        key: 'token',
+                        success(res) {
+                            wx.showToast({ title: `修改密码成功`, icon: 'success' });
+                            wx.redirectTo({ url: '/pagesHome/home/index' })
+                        }
+                    })
+                } else {
+                    wx.showToast({ title: `${res.errmsg}`, icon: 'none' });
+                }
+            }
+        }
+    },
+    // 查询其他信息
+    async searchOther() {
         const that = this;
+        let res;
+        // 性别
+        res = await app.$api('dictData', 'GET', { type: 'gender', is_use: '0' })
+        if (res.errcode == '0') that.setData({ genderList: res.data })
+        // 类别
+        res = await app.$api('dictData', 'GET', { type: 'type', is_use: '0' })
+        if (res.errcode == '0') that.setData({ typeList: res.data })
     },
 
     /**

+ 33 - 1
pagesMy/update/index.wxml

@@ -1,3 +1,35 @@
 <view class=" content main">
-    修改密码
+    <view class="one">
+        <form catchsubmit="toSave">
+            <view class="info">
+                <view class="info_1">
+                    <view class="label">
+                        账号:
+                    </view>
+                    <view class="value">
+                        <input disabled value="{{form.account}}" name="account" type="text" placeholder="" />
+                    </view>
+                </view>
+                <view class="info_1">
+                    <view class="label">
+                        新密码:
+                    </view>
+                    <view class="value">
+                        <input value="{{form.password}}" type='text' password name="password" placeholder="" />
+                    </view>
+                </view>
+                <view class="info_1">
+                    <view class="label">
+                        确认新密码:
+                    </view>
+                    <view class="value">
+                        <input value="{{form.is_password}}" password type='text' name="is_password" placeholder="" />
+                    </view>
+                </view>
+                <view class="btn">
+                    <button type="primary" formType="submit">保存</button>
+                </view>
+            </view>
+        </form>
+    </view>
 </view>

+ 41 - 1
pagesMy/update/index.wxss

@@ -1 +1,41 @@
-@import "../../app.wxss";
+@import "../../app.wxss";
+
+ .main {
+     padding: 2vw;
+ }
+
+ .main .one .info {
+     margin: 0 0 2vw 0;
+ }
+
+ .main .one .info .info_1 {
+     display: flex;
+     align-items: center;
+     border: 1px solid var(--rgb40E);
+     padding: 2vw;
+     border-radius: 5px;
+     margin: 0 0 3vw 0;
+ }
+
+ .main .one .info .info_1 .label {
+     font-size: 14px;
+     color: var(--rgb8b8);
+ }
+
+ .main .one .info .info_1 .value {
+     width: 68%;
+     flex-grow: 1;
+     font-size: 14px;
+ }
+ .main .one .btn {
+    display: flex;
+    align-items: center;
+    justify-content: center;
+ }
+
+ .main .one .btn button {
+     margin: 0 2vw;
+     background-color: var(--rgb40E);
+     background-image: linear-gradient(to right, var(--rgb3AB) , var(--rgb40E));
+     border-radius: 30rpx;
+ }