zs 1 рік тому
батько
коміт
85519c974e
3 змінених файлів з 18 додано та 11 видалено
  1. 1 0
      pagesMy/basic/index.js
  2. 15 10
      pagesMy/home/index.js
  3. 2 1
      project.private.config.json

+ 1 - 0
pagesMy/basic/index.js

@@ -100,6 +100,7 @@ Page({
             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.setStorage({ key: "token", res: arr.data })// 存用户信息到storage,以便之后判断用户是否登录
                 wx.showToast({ title: `信息提交成功`, icon: 'success' });
                 wx.navigateBack({ delta: 1 });
             } else {

+ 15 - 10
pagesMy/home/index.js

@@ -49,17 +49,22 @@ Page({
     async toAvatarUrl(e) {
         const that = this;
         const { avatarUrl } = e.detail
-        let res = await app.$apifile('files/ball/users/upload', null, avatarUrl)
-        res = JSON.parse(res);
-        if (res.errcode == '0') {
-            let icon = [{ id: res.id, name: res.name, uri: res.uri, url: `${app.globalData.fileserverUrl}` + res.uri }]
-            let arr = await app.$api(`user/${that.data.user._id}`, 'POST', { icon: icon });
-            if (arr.errcode == '0') {
-                wx.showToast({ title: `头像上传成功`, icon: 'success' });
-                that.search()
-            } else {
-                wx.showToast({ title: `${arr.errmsg}`, icon: 'error' });
+        if (that.data.user._id) {
+            let res = await app.$apifile('files/ball/users/upload', null, avatarUrl)
+            res = JSON.parse(res);
+            if (res.errcode == '0') {
+                let icon = [{ id: res.id, name: res.name, uri: res.uri, url: `${app.globalData.fileserverUrl}` + res.uri }]
+                let arr = await app.$api(`user/${that.data.user._id}`, 'POST', { icon: icon });
+                if (arr.errcode == '0') {
+                    wx.setStorage({ key: "token", data: arr.data })// 存用户信息到storage,以便之后判断用户是否登录
+                    wx.showToast({ title: `头像上传成功`, icon: 'success' });
+                    that.search()
+                } else {
+                    wx.showToast({ title: `${arr.errmsg}`, icon: 'error' });
+                }
             }
+        } else {
+            wx.navigateTo({ url: '/pagesCommon/login/index' })
         }
     },
     /**

+ 2 - 1
project.private.config.json

@@ -4,5 +4,6 @@
     "setting": {
         "compileHotReLoad": true,
         "urlCheck": false
-    }
+    },
+    "libVersion": "2.32.1"
 }