Commit f2f56c1e authored by Morson's avatar Morson

修改token同步问题

parent b2946922
<script> <script>
import './../.env.js' import "./../.env.js";
import { import { AnalysysAgent } from "@/utils/analysys_paas.js";
AnalysysAgent import util from "@/utils/util.js";
} from '@/utils/analysys_paas.js' export default {
import util from '@/utils/util.js' globalData: {
export default {
globalData:{
// 开发环境 // 开发环境
uniEnv:process.uniEnv, uniEnv: process.uniEnv,
// 登录凭证 // 登录凭证
token: '', token: "",
//授权提示 图标 //授权提示 图标
icon_auth_notice: 'https://qn-static.banshouhui.com/auth_notice.png', icon_auth_notice: "https://qn-static.banshouhui.com/auth_notice.png",
//授权提示新 图标 //授权提示新 图标
icon_auth_notice_new: 'https://qn-static.banshouhui.com/auth_notice_new.png', icon_auth_notice_new:
"https://qn-static.banshouhui.com/auth_notice_new.png",
// 服务规范教程视频 // 服务规范教程视频
service_standard: { service_standard: {
"course1": { course1: {
url: "https://qn-static.banshouhui.com/self-support/videoen.mp4", url: "https://qn-static.banshouhui.com/self-support/videoen.mp4",
title: "第一节 师傅考核规则", title: "第一节 师傅考核规则",
desc: "接单操作须知有助你快速了解充电桩安装业务,提高接单效率,请认真查看及学习。", desc:
"接单操作须知有助你快速了解充电桩安装业务,提高接单效率,请认真查看及学习。",
}, },
"course2": { course2: {
url: "https://qn-static.banshouhui.com/self-support/videoen.mp4", url: "https://qn-static.banshouhui.com/self-support/videoen.mp4",
title: "第二节 安装材料及工具", title: "第二节 安装材料及工具",
desc: "接单操作须知有助你快速了解充电桩安装业务,提高接单效率,请认真查看及学习。", desc:
"接单操作须知有助你快速了解充电桩安装业务,提高接单效率,请认真查看及学习。",
}, },
"course3": { course3: {
url: "https://qn-static.banshouhui.com/self-support/videoen.mp4", url: "https://qn-static.banshouhui.com/self-support/videoen.mp4",
title: "第三节 安装施工规范", title: "第三节 安装施工规范",
desc: "接单操作须知有助你快速了解充电桩安装业务,提高接单效率,请认真查看及学习。", desc:
"接单操作须知有助你快速了解充电桩安装业务,提高接单效率,请认真查看及学习。",
}, },
"course4": { course4: {
url: "https://qn-static.banshouhui.com/self-support/videoen.mp4", url: "https://qn-static.banshouhui.com/self-support/videoen.mp4",
title: "第四节 录单上传要求", title: "第四节 录单上传要求",
desc: "接单操作须知有助你快速了解充电桩安装业务,提高接单效率,请认真查看及学习。", desc:
"接单操作须知有助你快速了解充电桩安装业务,提高接单效率,请认真查看及学习。",
}, },
}, },
// 授权用户信息 // 授权用户信息
authUserInfo: '', authUserInfo: "",
// 用户入驻信息 // 用户入驻信息
settledInfo: {}, settledInfo: {},
}, },
onLaunch: function() { onLaunch: function () {
// 应用初始化(全局只触发一次) // 应用初始化(全局只触发一次)
let that = this let that = this;
that.globalData.token = util.getToken() that.globalData.token = util.getToken();
AnalysysAgent.registerSuperProperty("platform", "self-support"); AnalysysAgent.registerSuperProperty("platform", "self-support");
// 应用启动,或从后台进入前台显示 // 应用启动,或从后台进入前台显示
this.autoLogin() that.autoLogin();
}, },
onShow: function() { onShow: function () {
// 应用启动,或从后台进入前台显示 // 应用启动,或从后台进入前台显示
// this.autoLogin() // this.autoLogin()
}, },
onHide: function() { onHide: function () {
// 应用从前台进入后台 // 应用从前台进入后台
}, },
methods: { methods: {
async getBaseInfo(vm, callBack) { async getBaseInfo(vm, callBack) {
uni.showLoading({ uni.showLoading({
title: '加载中……' title: "加载中……",
}) });
const res = await vm.$u.api.getSettleBaseInfo() const res = await vm.$u.api.getSettleBaseInfo();
console.log(res,'res') console.log(res, "res");
if(res.code !==200){ if (res.code !== 200) {
uni.showToast({ uni.showToast({
title: res && res.message || '获取基本信息错误', title: (res && res.message) || "获取基本信息错误",
icon: 'none' icon: "none",
}); });
return false; return false;
} }
this.globalData.settledInfo = res.data this.globalData.settledInfo = res.data;
if (!res.data) { if (!res.data) {
return return;
} }
if(typeof callBack == 'function') { if (typeof callBack == "function") {
callBack(vm, res.data) callBack(vm, res.data);
} }
uni.hideLoading() uni.hideLoading();
return res.data return res.data;
}, },
/** /**
* 用户自动登录 * 用户自动登录
*/ */
autoLogin() { autoLogin() {
let that = this let that = this;
uni.login({ uni.login({
async success(res) { async success(res) {
if (res.code) { if (res.code) {
let params = { let params = {
code: res.code, code: res.code,
wxAppNo: 1, // 自营平台小程序 wxAppNo: 1, // 自营平台小程序
} };
let result = await that.$u.api.loginWechatAuth(params) let result = await that.$u.api.loginWechatAuth(params);
if (result) { if (result) {
if (result.code == 200 && result.data) { if (result.code == 200 && result.data) {
that.setUserData(result.data) that.setUserData(result.data);
that.getBaseInfo(that) that.getBaseInfo(that);
} }
} else { } else {
uni.showModal({ uni.showModal({
title: '请求失败', title: "请求失败",
content: result.message, content: result.message,
showCancel: false showCancel: false,
}); });
} }
uni.hideLoading() uni.hideLoading();
} else { } else {
uni.showModal({ uni.showModal({
title: '登录失败', title: "登录失败",
content: '未获取到code', content: "未获取到code",
}); });
} }
}, },
fail() { fail() {},
}
}); });
}, },
setUserData(userInfo) { setUserData(userInfo) {
if (userInfo && userInfo.token) { if (userInfo && userInfo.token) {
// 如果已经登录则直接获取相关信息 // 如果已经登录则直接获取相关信息
util.setOpenid(userInfo.wxopenid) util.setOpenid(userInfo.wxopenid);
util.setToken(userInfo.token) util.setToken(userInfo.token);
uni.setStorageSync('user-info', userInfo); this.$u.vuex("vuex_token", userInfo.token);
uni.setStorageSync("user-info", userInfo);
} else { } else {
util.setToken('') util.setToken("");
this.$u.vuex("vuex_token", "");
} }
}, },
...@@ -149,39 +151,39 @@ ...@@ -149,39 +151,39 @@
// 设备身份表示 // 设备身份表示
if (AnalysysAgent) { if (AnalysysAgent) {
let setProfile = { let setProfile = {
'openid': openid, openid: openid,
'unionid': unionid, unionid: unionid,
} };
setProfile = Object.assign(setProfile, userInfo) setProfile = Object.assign(setProfile, userInfo);
AnalysysAgent.profileSet(setProfile); AnalysysAgent.profileSet(setProfile);
} }
}, },
setUserId(userId) { setUserId(userId) {
// 用户id设置 // 用户id设置
if (AnalysysAgent) { if (AnalysysAgent) {
AnalysysAgent.alias(userId + '') AnalysysAgent.alias(userId + "");
} }
}, },
setUser(user) { setUser(user) {
// 用户附加属性 // 用户附加属性
if (AnalysysAgent) { if (AnalysysAgent) {
let userInfo = { let userInfo = {
'mobile': user.mobile, mobile: user.mobile,
'userfrom_id': user.uid, userfrom_id: user.uid,
'userfrom': '家维广场', userfrom: "家维广场",
'avatar': user.avatar, avatar: user.avatar,
'nickname': user.nickname, nickname: user.nickname,
'username': user.username, username: user.username,
'wxhuid': user.wxhuid, wxhuid: user.wxhuid,
'id': user.id, id: user.id,
'money': user.money, money: user.money,
'score': user.score score: user.score,
}; };
Object.keys(userInfo).map(key => { Object.keys(userInfo).map((key) => {
if (key && userInfo[key]) { if (key && userInfo[key]) {
AnalysysAgent.profileAppend(key, userInfo[key]) AnalysysAgent.profileAppend(key, userInfo[key]);
} }
}) });
} }
}, },
share(toShareProperties, trackProperties) { share(toShareProperties, trackProperties) {
...@@ -195,26 +197,26 @@ ...@@ -195,26 +197,26 @@
} }
}, },
initShare(option) { initShare(option) {
console.log(option, 'option-initShare') console.log(option, "option-initShare");
option = option || {} option = option || {};
if (AnalysysAgent && option.user_id) { if (AnalysysAgent && option.user_id) {
let shareUserInfo = { let shareUserInfo = {
'share_from_id': option.user_id || '', share_from_id: option.user_id || "",
'share_from_nickname': option.user_name || '', share_from_nickname: option.user_name || "",
} };
AnalysysAgent.registerSuperProperties(shareUserInfo); AnalysysAgent.registerSuperProperties(shareUserInfo);
} }
}, },
/* ------------------------- 数据埋点end ------------------------------ */ /* ------------------------- 数据埋点end ------------------------------ */
} },
} };
</script> </script>
<style> <style>
/*每个页面公共css */ /*每个页面公共css */
</style> </style>
<style lang="scss"> <style lang="scss">
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */ /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
@import "uview-ui/index.scss"; @import "uview-ui/index.scss";
@import '@/common/index.scss'; @import "@/common/index.scss";
</style> </style>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment