Преглед изворни кода

Merge branch 'master' of http://git.cc-lotus.info/ball-court/court-badminton

guhongwei пре 2 година
родитељ
комит
08da20a9cb

+ 2 - 0
app.json

@@ -1,5 +1,6 @@
 {
     "pages": [
+
         "pages/index/index",
         "pages/register/index",
         "pages/home/index",
@@ -11,6 +12,7 @@
         "pages/usermymatch/index",
         "pages/setting/index",
         "pages/setting/basic",
+        "pages/setting/contact",
         "pages/test/index"
     ],
     "usingComponents": {

+ 1 - 1
pages/my/index.js

@@ -59,7 +59,7 @@ Page({
      * 生命周期函数--监听页面显示
      */
     onShow: function () {
-
+        this.watchLogin();
     },
 
     /**

+ 19 - 2
pages/my/userInfo.js

@@ -7,7 +7,7 @@ Page({
     data: {
         frameStyle: { useTop: true, name: '个人信息', leftArrow: true, useBar: false },
         icon: '/image/icon.jpg',
-        form: { id: "1", img_url: "/image/icon.jpg", name: "测试", gender: '男', phone: '13174420325', email: '' },
+        form: {},
     },
     // 返回
     back: function () {
@@ -18,7 +18,24 @@ Page({
      */
     onLoad: function (options) {
         const that = this;
-
+        // 监听用户是否登录
+        that.watchLogin();
+    },
+    // 监听用户是否登录
+    watchLogin: async function () {
+        const that = this;
+        wx.getStorage({
+            key: 'user',
+            success: async res => {
+                const arr = await app.$get(`/newCourt/api/user/${res.data.openid}`);
+                if (arr.errcode == '0') {
+                    that.setData({ form: arr.data });
+                }
+            },
+            fail: res => {
+                wx.redirectTo({ url: '/pages/index/index', })
+            }
+        })
     },
     /**
      * 生命周期函数--监听页面初次渲染完成

+ 1 - 1
pages/my/userInfo.wxml

@@ -9,7 +9,7 @@
                 <view class="content">
                     <view class="label">用户头像</view>
                     <view class="value">
-                        <image class="img" src="{{form.img_url||icon}}"></image>
+                        <image class="img" src="{{form.icon[0].url||icon}}"></image>
                     </view>
                 </view>
                 <view class="content">

+ 52 - 5
pages/setting/basic.js

@@ -16,9 +16,9 @@ Page({
         genderList: gender,
     },
     initValidate() {
-        const rules = { nickname: { required: true }, phone: { required: true, tel: true }, password: { required: false }, status: { required: true } }
+        const rules = { name: { required: true }, phone: { required: true, tel: true }, gender: { required: false }, email: { required: true } }
         // 验证字段的提示信息,若不传则调用默认的信息
-        const messages = { nickname: { required: '请输入昵称', }, phone: { required: '请输入手机号', }, password: { required: '请输入登录密码', }, status: { required: '请选择状态' } };
+        const messages = { name: { required: '请输入用户名', }, phone: { required: '请输入手机号', }, gender: { required: '请选择性别', }, email: { required: '请输入邮箱' } };
         this.WxValidate = new WxValidate(rules, messages)
     },
     // 返回
@@ -44,15 +44,62 @@ Page({
         const that = this;
         let index = e.detail.value;
         let value = that.data.genderList[index];
-        that.setData({ 'form.gender': value });
+        that.setData({ 'form.gender': value.value });
+    },
+    // 提交登录
+    onSubmit: async function (e) {
+        const that = this;
+        const params = e.detail.value;
+        const data = that.data.form;
+        if (!this.WxValidate.checkForm(params)) {
+            const error = this.WxValidate.errorList[0];
+            wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
+            return false
+        } else {
+            let arr;
+            if (data._id) {
+                if (!params.icon) params.icon = that.data.icon;
+                arr = await app.$post(`/newCourt/api/user/${data._id}`, params);
+                if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); }
+                else wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
+            } else {
+                arr = await app.$get(`/newCourt/api/user`, { phone: params.phone });
+                if (arr.errcode == '0' && arr.total > 0) wx.showToast({ title: `该账号已有用户使用`, icon: 'error', duration: 2000 })
+                else {
+                    params.icon = that.data.icon;
+                    arr = await app.$post(`/newCourt/api/user`, params);
+                    if (arr.errcode == '0') { wx.showToast({ title: `添加信息完成`, icon: 'success', duration: 2000 }); that.back(); }
+                    else wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
+                }
+            }
+        }
     },
-
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad: function (options) {
         const that = this;
-
+        //验证规则函数
+        that.initValidate();
+        // 监听用户是否登录
+        that.watchLogin();
+    },
+    // 监听用户是否登录
+    watchLogin: async function () {
+        const that = this;
+        wx.getStorage({
+            key: 'user',
+            success: async res => {
+                const arr = await app.$get(`/newCourt/api/user/${res.data.openid}`);
+                if (arr.errcode == '0') {
+                    if (arr.data.icon) that.setData({ icon: arr.data.icon });
+                    that.setData({ form: arr.data });
+                }
+            },
+            fail: res => {
+                wx.redirectTo({ url: '/pages/index/index', })
+            }
+        })
     },
     /**
      * 生命周期函数--监听页面初次渲染完成

+ 6 - 0
pages/setting/basic.less

@@ -27,5 +27,11 @@
                 }
             }
         }
+
+        .btn {
+            width: 96vw;
+            display: flex;
+            margin: 50px 0;
+        }
     }
 }

+ 16 - 2
pages/setting/basic.wxml

@@ -2,6 +2,18 @@
     <view slot="info" class="container main">
         <view class="one">
             <form catchsubmit="onSubmit">
+                <view class="content" style="display: none;">
+                    <view class="label">用户id:</view>
+                    <view class="value"><input name="id" value="{{form.id}}" placeholder="请输入用户id" /></view>
+                </view>
+                <view class="content" style="display: none;">
+                    <view class="label">openid:</view>
+                    <view class="value"><input name="openid" value="{{form.openid}}" placeholder="请输入openid" /></view>
+                </view>
+                <view class="content" style="display: none;">
+                    <view class="label">身份证:</view>
+                    <view class="value"><input name="card" value="{{form.card}}" placeholder="请输入身份证" /></view>
+                </view>
                 <view class="content">
                     <view class="label">用户名</view>
                     <view class="value"><input name="name" value="{{form.name}}" placeholder="请输入用户名" /></view>
@@ -15,8 +27,7 @@
                 <view class="content">
                     <view class="label">性别</view>
                     <view class="value">
-                        <!-- <van-picker value-key="value" columns="{{ form.gender }}" bind:change="genderChange" /> -->
-                        <picker name="gender" bindchange="genderChange" value="{{form.gender}}" range="{{genderList}}">
+                        <picker name="gender" bindchange="genderChange" value="{{form.gender}}" range-key='value' range="{{genderList}}">
                             <view class="input">{{form.gender||'选择性别'}}</view>
                         </picker>
                     </view>
@@ -29,6 +40,9 @@
                     <view class="label">邮箱</view>
                     <view class="value"><input name="email" value="{{form.email}}" placeholder="请输入邮箱" /></view>
                 </view>
+                <view class="btn">
+                    <button type="primary" size="mini" formType="submit">提交保存</button>
+                </view>
             </form>
         </view>
     </view>

+ 5 - 0
pages/setting/basic.wxss

@@ -24,3 +24,8 @@
 .main .one .content .value input {
   text-align: right;
 }
+.main .one .btn {
+  width: 96vw;
+  display: flex;
+  margin: 50px 0;
+}

+ 69 - 0
pages/setting/contact.js

@@ -0,0 +1,69 @@
+const app = getApp()
+Page({
+
+    /**
+     * 页面的初始数据
+     */
+    data: {
+        frameStyle: { useTop: true, name: '联系我们', leftArrow: true, useBar: false },
+    },
+    // 返回
+    back: function () {
+        wx.navigateBack({ delta: 1 })
+    },
+    /**
+     * 生命周期函数--监听页面加载
+     */
+    onLoad: function (options) {
+        const that = this;
+
+    },
+    /**
+     * 生命周期函数--监听页面初次渲染完成
+     */
+    onReady: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面显示
+     */
+    onShow: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面隐藏
+     */
+    onHide: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面卸载
+     */
+    onUnload: function () {
+
+    },
+
+    /**
+     * 页面相关事件处理函数--监听用户下拉动作
+     */
+    onPullDownRefresh: function () {
+
+    },
+
+    /**
+     * 页面上拉触底事件的处理函数
+     */
+    onReachBottom: function () {
+
+    },
+
+    /**
+     * 用户点击右上角分享
+     */
+    onShareAppMessage: function () {
+
+    }
+})

+ 6 - 0
pages/setting/contact.json

@@ -0,0 +1,6 @@
+{
+  "component": true,
+  "usingComponents": {
+    "mobile-main": "/commpents/mobile-frame/index"
+  }
+}

+ 5 - 0
pages/setting/contact.less

@@ -0,0 +1,5 @@
+.main {
+    height: 88vh;
+    background-color: #ff0000;
+  }
+  

+ 5 - 0
pages/setting/contact.wxml

@@ -0,0 +1,5 @@
+<mobile-main frameStyle="{{frameStyle}}" bind:back="back">
+    <view slot="info" class="container main">
+        联系我们
+    </view>
+</mobile-main>

+ 4 - 0
pages/setting/contact.wxss

@@ -0,0 +1,4 @@
+.main {
+  height: 88vh;
+  background-color: #ff0000;
+}