zs hace 2 años
padre
commit
feaf1a1b5a

+ 20 - 8
pages/index/index.js

@@ -48,15 +48,27 @@ Page({
     // 监听用户是否登录
     watchLogin: async function () {
         const that = this;
-        wx.getStorage({
-            key: 'token',
-            success: async res => {
-                wx.redirectTo({ url: '/pagesHome/home/index' })
+        wx.login({
+            success: async (arr) => {
+                const { code: js_code } = arr;
+                const { wx_config } = app.globalData;
+                wx.getStorage({
+                    key: 'token',
+                    success(res) {
+                        if (res.data) wx.redirectTo({ url: '/pagesHome/home/index' })
+                    },
+                    async fail(err) {
+                        const aee = await app.$api('token/app', 'GET', { js_code: js_code, config: wx_config.config });
+                        if (aee.errcode == '0') {
+                            wx.setStorage({ key: "openid", data: aee.data.openid })
+                            wx.redirectTo({ url: '/pagesCommon/login/index' })
+                        } else {
+                            wx.showToast({ title: `${aee.errmsg}`, icon: 'none' });
+                        }
+                    }
+                })
             },
-            fail: res => {
-                return wx.redirectTo({ url: '/pagesCommon/login/index' })
-            }
-        })
+        });
     },
     /**
      * 生命周期函数--监听页面隐藏

+ 7 - 0
pagesCommon/login/index.js

@@ -36,6 +36,7 @@ Page({
             wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
             return false
         } else {
+            params.openid = that.data.form.openid
             const res = await app.$api('user/login', 'POST', params);
             if (res.errcode === 0) {
                 app.globalData.userInfo = res.data;//存用户信息到app.js
@@ -59,6 +60,7 @@ Page({
             if (params.password !== params.is_password) {
                 wx.showToast({ title: '密码输入不一致', duration: 2000, icon: 'error', })
             } else {
+                params.openid = that.data.form.openid
                 delete params.is_password
                 const res = await app.$api('user', 'POST', params);
                 if (res.errcode === 0) {
@@ -98,6 +100,11 @@ Page({
     // 查询通知
     async search() {
         const that = this;
+        wx.getStorage({
+            key: 'openid',
+            async success(res) { that.setData({ 'form.openid': res.data }) },
+            fail(err) { console.log(err); }
+        })
     },
     /**
      * 生命周期函数--监听页面初次渲染完成

+ 111 - 5
pagesMy/basic/index.js

@@ -1,20 +1,126 @@
 const app = getApp()
+import WxValidate from '../../utils/wxValidate'
+const moment = require("../../utils/moment.min");
 Page({
+
+    /**
+     * 页面的初始数据
+     */
     data: {
-        info: {}
+        form: {},
+        // 性别
+        genderList: [],
+        // 类别
+        typeList: [],
+    },
+    initValidate() {
+        const rules = { name: { required: true } }
+        const messages = { name: { required: '请输入姓名' } };
+        this.WxValidate = new WxValidate(rules, messages)
     },
     /**
      * 生命周期函数--监听页面加载
      */
-    onLoad(options) {
+    async onLoad(options) {
         const that = this;
         wx.showLoading({ title: '加载中', mask: true })
-        that.search()
+        //验证规则函数
+        that.initValidate();
+        await that.searchOther()
+        await 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;
+                    if (form && form._id) {
+                        // 性别
+                        if (form.gender) form.gender_name = that.getDict(form.gender, 'gender')
+                        // 工作状态
+                        if (form.type) form.type_name = that.getDict(form.type, 'type')
+                    } else {
+                        form.status = '0';
+                    }
+                } else {
+                    wx.showToast({ title: `${aee.errmsg}`, icon: 'error' });
+                }
+                that.setData({ form })
+            },
+            fail(err) {
+                console.log(err);
+            }
+        })
+    },
+    // 过滤字典表
+    getDict(value, model) {
+        const that = this;
+        if (value) {
+            let list = that.data[model + 'List']
+            let data = list.find(i => i.value == value);
+            if (data) return data.label
+            else return '暂无'
+        }
+    },
+    // 选择性别
+    genderChange(e) {
+        const that = this;
+        const index = e.detail.value;
+        let data = that.data.genderList[index];
+        if (data) {
+            that.setData({ 'form.gender': data.value })
+            that.setData({ 'form.gender_name': data.label })
+        }
+    },
+    // 选择类别
+    typeChange(e) {
+        const that = this;
+        // 所取数据
+        const index = e.detail.value;
+        // 选择项
+        let data = that.data.typeList[index];
+        if (data) {
+            that.setData({ 'form.type': data.value })
+            that.setData({ 'form.type_name': data.label })
+        }
+    },
+    // 提交保存
+    async toSave(e) {
+        const that = this;
+        const parmas = e.detail.value;
+        if (!this.WxValidate.checkForm(parmas)) {
+            const error = that.WxValidate.errorList[0];
+            wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
+            return false
+        } else {
+           // 判断id使用
+           let form = that.data.form;
+           let res;
+           if (form._id) res = await app.$api(`user/${form._id}`, 'POST', parmas);
+           else res = await app.$api('user', 'POST', parmas);
+           if (res.errcode == '0') {
+               wx.showToast({ title: `信息提交成功`, icon: 'success' });
+               that.search()
+           } 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 })
     },
 
     /**

+ 81 - 1
pagesMy/basic/index.wxml

@@ -1,3 +1,83 @@
 <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.name}}" name="name" type="text" placeholder="" />
+                    </view>
+                </view>
+                <view class="info_1">
+                    <view class="label">
+                        性别:
+                    </view>
+                    <view class="value">
+                        <picker bindchange="genderChange" value="{{form.gender}}" name="gender" range="{{genderList}}" range-key='label'>
+                            <view class="picker">
+                                {{form.gender_name||''}}
+                            </view>
+                        </picker>
+                    </view>
+                </view>
+                <view class="info_1">
+                    <view class="label">
+                        年龄:
+                    </view>
+                    <view class="value">
+                        <input value="{{form.age}}" name="age" type="text" placeholder="" />
+                    </view>
+                </view>
+                <view class="info_1">
+                    <view class="label">
+                        用户类别:
+                    </view>
+                    <view class="value">
+                        <picker bindchange="typeChange" value="{{form.type}}" name="type" range="{{typeList}}" range-key='label'>
+                            <view class="picker">
+                                {{form.type_name||''}}
+                            </view>
+                        </picker>
+                    </view>
+                </view>
+                <view class="info_1">
+                    <view class="label">
+                        工作单位:
+                    </view>
+                    <view class="value">
+                        <input value="{{form.work}}" name="work" type="text" placeholder="" />
+                    </view>
+                </view>
+                <view class="info_1">
+                    <view class="label">
+                        手机号:
+                    </view>
+                    <view class="value">
+                        <input value="{{form.phone}}" name="phone" type="text" placeholder="" />
+                    </view>
+                </view>
+                <view class="info_1">
+                    <view class="label">
+                        电子邮箱:
+                    </view>
+                    <view class="value">
+                        <input value="{{form.email}}" name="email" type="text" placeholder="" />
+                    </view>
+                </view>
+                <view class="btn">
+                    <button type="primary" formType="submit">保存</button>
+                </view>
+            </view>
+        </form>
+    </view>
 </view>

+ 41 - 1
pagesMy/basic/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;
+ }

+ 1 - 1
project.config.json

@@ -42,7 +42,7 @@
     },
     "compileType": "miniprogram",
     "libVersion": "2.19.4",
-    "appid": "wx8cdd28824dfcdf19",
+    "appid": "wx23c71bee5876d1b9",
     "projectname": "miniprogram-92",
     "condition": {},
     "editorSetting": {