123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import Dialg from "../../miniprogram_npm/@vant/weapp/dialog/dialog";
- import { tabberFunc } from "../../utils/util";
- const app = getApp();
- Page({
- data: {
- waveimg: "../../assets/login/wave.svg",
- // 用户信息
- login: {},
- // 列表
- items: [
- { imgurl: 'loading', title: "更新资料", require: true, success () { this.updateFunc() } },
- { imgurl: 'punch', title: "草稿箱", require: true, success () { wx.navigateTo({ url: '/pages/template/index?data=drafts', }) } },
- { imgurl: 'form', title: "已填报", require: true, success () { wx.navigateTo({ url: '/pages/template/index?data=provided', }) } }
- ],
- update_lock: false,//更新资料按钮锁
- subscriber_lock: false,//订阅消息按钮锁
- },
- // tabber
- NavChange (e) {
- let { active, path } = e.currentTarget.dataset;
- tabberFunc(active, path)
- },
- // 更新资料
- async updateFunc () {
- function getUserProfile () {
- return new Promise((resolve, reject) => {
- wx.getUserProfile({
- desc: '用于完善会员资料',
- success: (res) => {
- let { encryptedData, iv } = res, { appId: appid } = app.globalData.mustArg, { openid } = app.globalData.user;
- resolve({ encryptedData, iv, appid, openid })
- },
- })
- })
- }
- try {
- let { encryptedData, iv, appid, openid } = await getUserProfile();
- let res = await wx.$request({
- method: "post", url: "/account/setUserInfo/", data: {
- appid, openid, iv, encryptedData
- },
- });
- let { face, name } = res.data;
- this.setData({ login: { state: name, imgurl: face } });
- app.globalData.mustArg = { ...app.globalData.mustArg, encryptedData, iv };
- app.globalData.user = { ...app.globalData.user, face, name }
- } catch (err) { wx.$err(err) }
- },
- // 功能事件
- onClickFunc (e) {
- let { index } = e.currentTarget.dataset, { items } = this.data;
- wx.getStorageSync('token') ?
- items[index]['success'].bind(this)() :
- Dialg.confirm({ message: "您尚未登录,不能操作该功能!", confirmButtonText: '微信快捷登录', confirmButtonOpenType: "getPhoneNumber" }).then(res => {
- }).catch(() => { })
- ;
- },
- // 登录
- async getphonenumber (e) {
- try {
- if (!e.detail.hasOwnProperty('iv')) return false;
- let { encryptedData, iv } = e.detail, { appId: appid } = app.globalData.mustArg, { openid } = app.globalData.user;
- let res = await wx.$request({ url: "/account/wxbind/", data: { appid, openid, encryptedData, iv }, method: "post" });
- let { face, name, tel, token, type, user_id } = res.data;
- wx.setStorageSync("token", token ? 'JWT ' + token : '');
- let login = {
- imgurl: token ? face : app.globalData.mustArg.userInfo.avatarUrl,
- name: token ? name : "微信快捷登录",
- state: token ? true : false
- };
- this.setData({ login });
- app.globalData.user = { ...app.globalData.user, face, name, tel, token, type, user_id };
- } catch (err) { wx.$err(err) }
- },
- onSelect (event) {
- },
- onLoad: function (options) {
- },
- onReady: function () {
- },
- onShow: function () {
- let login = {
- imgurl: (wx.getStorageSync('token') && app.globalData.user.face) ? app.globalData.user.face : app.globalData.mustArg.userInfo.avatarUrl,
- name: wx.getStorageSync('token') ? app.globalData.user.name : "微信快捷登录",
- state: wx.getStorageSync('token') ? true : false
- };
- this.setData({ login });
- },
- onHide: function () {
- },
- onUnload: function () {
- },
- onPullDownRefresh: function () {
- },
- onReachBottom: function () {
- },
- onShareAppMessage: function () {
- }
- })
|