Commit 4cf29477 authored by 高铭波's avatar 高铭波

缓存图片优化

埋点问题修复
登录模块优化
parent feb6bf37
......@@ -38,9 +38,7 @@ export default {
"接单操作须知有助你快速了解充电桩安装业务,提高接单效率,请认真查看及学习。",
},
},
// 授权用户信息
authUserInfo: "",
// 退出登录
logout: false,
navHeight: 0, //导航栏高度
rpxScreenHeight: 0, // 照相视框高度
......@@ -153,14 +151,10 @@ export default {
wxAppNo: that.globalData.wxAppNo, // 自营平台小程序
};
let result = await that.$u.api.loginWechatAuth(params);
console.log("result", result)
if (
result &&
result.code == 200 &&
result.data &&
result.data.token
) {
that.setUserData(result.data);
if (result && result.code == 200 && result.data && result.data.token) {
login.setUserData(result.data, this);
this.profileSet(this)
this.profileAppend(this)
} else {
uni.navigateTo({
url: "pages/login/index",
......@@ -174,25 +168,6 @@ export default {
}
});
},
setUserData(userInfo, that) {
let self = that ? that : this
if (userInfo && userInfo.token) {
// 如果已经登录则直接获取相关信息
self.$u.vuex("vuex_token", userInfo.token);
self.$u.vuex("vuex_user", userInfo);
self.$u.vuex("vuex_wx_uid", userInfo.wxopenid);
this.track('auth_login', {
auth_token: userInfo.token,
auth_user: userInfo,
auth_wx_uid: userInfo.wxopenid
});
} else {
self.$u.vuex("vuex_token", "");
self.$u.vuex("vuex_user", null);
self.$u.vuex("vuex_wx_uid", "");
}
self.$u.vuex("vuex_settled", null);
},
/* 版本更新 */
async updateApp() {
......@@ -229,41 +204,32 @@ export default {
AnalysysAgent.track("self_support_" + event, properties);
}
},
identify(userInfo, openid, unionid = null) {
// 设备身份表示
if (AnalysysAgent) {
let setProfile = {
openid: openid,
unionid: unionid,
};
setProfile = Object.assign(setProfile, userInfo);
AnalysysAgent.profileSet(setProfile);
}
},
setUserId(userId) {
// 用户id设置
profileSet(vm) {
// 设备身份标识
if (AnalysysAgent) {
AnalysysAgent.alias(userId + "");
let user = vm.$u.deepClone(vm.vuex_user);
let profile = vm.$u.deepClone(vm.vuex_auth_user);
profile.openid = user.wxopenid || profile.openid
profile.unionid = user.unionid || profile.unionid || null
AnalysysAgent.profileSet(profile);
}
},
setUser(user) {
// 用户附加属性
profileAppend(vm) {
if (AnalysysAgent) {
let userInfo = {
mobile: user.mobile,
userfrom_id: user.uid,
userfrom: "自营平台",
avatar: user.avatar,
nickname: user.nickname,
username: user.username,
wxhuid: user.wxhuid,
id: user.id,
money: user.money,
score: user.score,
let user = vm.$u.deepClone(vm.vuex_user);
// 用户id设置
AnalysysAgent.alias(user.id + "");
// 用户附加属性
let profile = {
userfrom: "自营平台",
id: user.id,
mobile: user.mobile,
loginName: user.loginName,
source: user.score,
};
Object.keys(userInfo).map((key) => {
if (key && userInfo[key]) {
AnalysysAgent.profileAppend(key, userInfo[key]);
Object.keys(profile).map((key) => {
if (key && profile[key]) {
AnalysysAgent.profileAppend(key, profile[key]);
}
});
}
......
......@@ -18,8 +18,12 @@ let learnApiFun = function(vm){
/* 获取考试结果 */
let getExamResult = async (examId, params = {}) => await vm.$u.post(sysApiUrl + '/wxh-worker-rest/rest/exam/serviceRule/userExamInfo/' + vm.vuex_token + '?examId=' + examId, params);
/* 申请考试 */
let applyExam = async (examId, params = {}) => await vm.$u.post(sysApiUrl + '/wxh-worker-rest/rest/exam/serviceRule/' + vm.vuex_token + '?examId=' + examId, params);
/* 获取下一题 */
let getNextQuestion = async (userExamId, questionId, userAnswerIds, params = {}) => await vm.$u.post(sysApiUrl + '/wxh-worker-rest/rest/exam/serviceRule/next/' + vm.vuex_token + '?userExamId=' + userExamId + '&questionId=' + questionId + '&userAnswerIds=' + (userAnswerIds || "9999"), params);
const learnApi = {
getTrainingNoticeList,CourseList,ChapterDetails,CourseSection,updateLearnCourses,getExamResult
getTrainingNoticeList,CourseList,ChapterDetails,CourseSection,updateLearnCourses,getExamResult,applyExam,getNextQuestion
}
return learnApi
}
......
......@@ -32,6 +32,7 @@
</template>
<script>
import util from '@/utils/util.js'
export default {
props: {
type: { // exclusive:专属; mine:我的页面客服; pop:弹窗;
......@@ -44,13 +45,14 @@
},
computed: {
cusQrcode() {
return process.uniEnv.qn_base_url + (this.isMine ? 'erweima-rk.png' : 'dingdanzhushou-n.png')
},
kefuzxiaoxiImage() {
return process.uniEnv.qn_base_url + 'kefuzxiaoxi.png'
let src = this.isMine ? 'erweima-rk.png' : 'dingdanzhushou-n.png';
return util.imageCache(this, src)
},
kefuzxiaoxiImage() {
return util.imageCache(this, 'kefuzxiaoxi.png')
},
minekefutuImage() {
return process.uniEnv.qn_base_url + this.imageName
return util.imageCache(this, this.imageName)
},
imageName() {
return this.isMine ? 'kefufuwu-n.png' : 'kefutuzs.png'
......@@ -252,19 +254,19 @@
}
.settle-button {
margin-bottom: 14rpx;
width: 400rpx;
height: 104rpx;
font-size: 32rpx;
background-color: #2272FF;
border-radius: 52rpx;
line-height: 104rpx;
font-weight: bold;
&.is-mine {
width: 300rpx;
height: 80rpx;
border-radius: 40rpx;
line-height: 80rpx;
margin-bottom: 14rpx;
width: 400rpx;
height: 104rpx;
font-size: 32rpx;
background-color: #2272FF;
border-radius: 52rpx;
line-height: 104rpx;
font-weight: bold;
&.is-mine {
width: 300rpx;
height: 80rpx;
border-radius: 40rpx;
line-height: 80rpx;
}
}
......@@ -283,4 +285,4 @@
}
}
}
</style>
</style>
......@@ -98,7 +98,7 @@
<text class="font-default-color" :class="{'font-active-color':courselist[2].percent}" v-text="courselist[2].status"></text>
</view>
</view>
<!-- <view class="learn-class1 u-margin-left-30" @click="goPlay(courselist[3])">
<view class="learn-class1 u-margin-left-30" @click="goPlay(courselist[3])">
<image class="learn-img" :src="courselist[3].pic" mode=""></image>
<image class="bofang" :src="bofang" mode=""></image>
<view class="learn-desc">
......@@ -114,7 +114,7 @@
</u-line-progress>
<text class="font-default-color" :class="{'font-active-color':courselist[3].percent}" v-text="courselist[3].status"></text>
</view>
</view> -->
</view>
</view>
</scroll-view>
</swiper-item>
......@@ -192,15 +192,15 @@ var json = {
id: 173,
sectionId: "",
},
// {
// title: "充电桩安装要点提示",
// desc: "在充电装安装过程中需要着重注意的要点",
// pic: process.uniEnv.qn_base_url + "cdz-3x-v2.png",
// percent: 0,
// status: "",
// id: 173,
// sectionId: "",
// },
{
title: "充电桩安装要点提示",
desc: "在充电装安装过程中需要着重注意的要点",
pic: process.uniEnv.qn_base_url + "cdz-3x-v2.png",
percent: 0,
status: "",
id: 173,
sectionId: "",
},
],
test: [
{
......@@ -230,15 +230,15 @@ var json = {
id: 151,
sectionId: "",
},
// {
// title: "充电桩安装要点提示",
// desc: "在充电装安装过程中需要着重注意的要点",
// pic: process.uniEnv.qn_base_url + "cdz-3x-v2.png",
// percent: 0,
// status: "",
// id: 151,
// sectionId: "",
// },
{
title: "充电桩安装要点提示",
desc: "在充电装安装过程中需要着重注意的要点",
pic: process.uniEnv.qn_base_url + "cdz-3x-v2.png",
percent: 0,
status: "",
id: 151,
sectionId: "",
},
],
prod: [
{
......@@ -268,15 +268,15 @@ var json = {
id: 599,
sectionId: "",
},
// {
// title: "学习-我的模块",
// desc: "学习-我的模块",
// pic: process.uniEnv.qn_base_url + "yaodiantishi.png",
// percent: 0,
// status: "",
// id: 600,
// sectionId: "",
// },
{
title: "学习-我的模块",
desc: "学习-我的模块",
pic: process.uniEnv.qn_base_url + "yaodiantishi.png",
percent: 0,
status: "",
id: 600,
sectionId: "",
},
],
};
......@@ -419,16 +419,16 @@ export default {
id: courseListJson[2].id,
sectionId: courseListJson[2].sectionId,
}
// ,
// {
// title: courseListJson[3].title,
// desc: courseListJson[3].desc,
// percent: courseListJson[3].percent,
// status: courseListJson[3].status,
// pic: courseListJson[3].pic,
// id: courseListJson[3].id,
// sectionId: courseListJson[3].sectionId,
// },
,
{
title: courseListJson[3].title,
desc: courseListJson[3].desc,
percent: courseListJson[3].percent,
status: courseListJson[3].status,
pic: courseListJson[3].pic,
id: courseListJson[3].id,
sectionId: courseListJson[3].sectionId,
},
],
examList: [
{
......@@ -695,55 +695,54 @@ export default {
let length = this.examList.length;
for (let i = 0; i < length; i++) {
let examId = this.examList[i].id;
this.$u.api
.getExamResult(examId)
.then((res) => {
if (res.code != 200) {
console.log("getUserExamInfo 200 err");
uni.showToast({
icon: "none",
title: "获取考试信息失败",
});
}
this.examList[i].examId = res.data.id;
this.examList[i].examStatus = res.data.examStatus; //i;//
this.examList[i].questionTime = res.data.questionTime;
let examResult = res.data.examLevelResult;
this.examList[i].status =
examResult != "" ? examResult : "未通过";
//动态获取条件
let ruleDisc = res.data.ruleDisc;
let targetIndex = ruleDisc.indexOf("(");
if (targetIndex) {
this.examList[i].condition = ruleDisc
.substr(targetIndex + 1)
.replace(")", "");
}
// examStatus 用户考试状态 0考试中 1考试完成 2未参与
that.exam = res.data;
if (res.data.examStatus == 2) {
return;
}
if (res.data.examStatus == 1) {
that.examList[i].isComplete =
this.examList[i].status == "已通过";
that.examScore = res.data.examScore;
return;
}
if (res.data.examStatus == 0) {
that.userExamId = res.data.id;
}
})
.catch((err) => {
uni.hideLoading();
this.$u.api.getExamResult(examId)
.then((res) => {
if (res.code != 200) {
console.log("getUserExamInfo 200 err");
uni.showToast({
icon: "none",
title: "获取考试信息失败",
});
}
this.examList[i].examId = res.data.id;
this.examList[i].examStatus = res.data.examStatus; //i;//
this.examList[i].questionTime = res.data.questionTime;
let examResult = res.data.examLevelResult;
this.examList[i].status =
examResult != "" ? examResult : "未通过";
//动态获取条件
let ruleDisc = res.data.ruleDisc;
let targetIndex = ruleDisc.indexOf("(");
if (targetIndex) {
this.examList[i].condition = ruleDisc
.substr(targetIndex + 1)
.replace(")", "");
}
// examStatus 用户考试状态 0考试中 1考试完成 2未参与
that.exam = res.data;
if (res.data.examStatus == 2) {
return;
}
if (res.data.examStatus == 1) {
that.examList[i].isComplete =
this.examList[i].status == "已通过";
that.examScore = res.data.examScore;
return;
}
if (res.data.examStatus == 0) {
that.userExamId = res.data.id;
}
})
.catch((err) => {
uni.hideLoading();
uni.showToast({
icon: "none",
title: "获取考试信息失败",
});
});
}
},
//跳转到assessment页面
......
......@@ -37,6 +37,8 @@
</template>
<script>
import util from '@/utils/util.js'
import login from "@/utils/login.js";
const app = getApp();
export default {
data() {
......@@ -121,10 +123,10 @@
return this.avatar || this.placeholderImage
},
wodebeijingImage() {
return this.qnPath + 'wodebeijing.png'
return util.imageCache(this, 'wodebeijing.png')
},
placeholderImage() {
return this.qnPath + 'touxiang.png'
return util.imageCache(this, 'touxiang.png')
},
headImageStyle() {
return this.avatar ? 'width:136rpx; height:136rpx;border-radius:68rpx' : 'width:144rpx; height:144rpx;border-radius:72rpx'
......@@ -174,12 +176,12 @@
this.$u.route({url: "pages/login/index"})
},
logout() {
app.setUserData({}, this)
login.setUserData({}, this);
app.globalData.logout = true
},
async allowLogin() {
let res = await this.$u.api.allowLogin()
if (res && res.code == 200) {
let res = await this.$u.api.allowLogin()
if (res && res.code == 200) {
this.showSuperButton = res.data === true
}
......
......@@ -95,7 +95,8 @@ export default {
timer: null,
isComplete: false, // 是否已经考试完成判定
examInfo: null,
isLoadQuestion: true
isLoadQuestion: true,
isOnLoad: true
};
},
computed: {
......@@ -116,9 +117,8 @@ export default {
getApp().trackPage('学习考试答题页')
this.examId = e.examId;
this.userExamId = e.userExamId;
this.getNext();
// this.applyExam();
// this.getUserExamInfo();
this.getUserExamInfo();
// this.getNext();
},
onUnload() {
clearTimeout(this.timer);
......@@ -176,14 +176,6 @@ export default {
const result = txt.replace(reg, "");
return result;
},
//开始考试 点击
startClick: function () {
this.isStart = true;
//this.getData()
//this.applyExam()
this.getUserExamInfo();
},
gotoLogin() {
uni.navigateTo({
url: "/pages/login/wxlogin",
......@@ -197,64 +189,59 @@ export default {
});
let that = this;
uni.request({
url:
systemApiUrl +
"/wxh-worker-rest/rest/exam" +
"/serviceRule/userExamInfo/" +
that.vuex_token +
"?examId=" +
this.examId,
method: "POST",
data: {
//examId:this.examId,
},
header: {
"Content-Type": "application/x-www-form-urlencoded",
},
success: (res) => {
uni.hideLoading();
if (!res.data) {
let examId = that.examId;
this.$u.api.getExamResult(examId)
.then((res) => {
uni.hideLoading();
if (!res.data) {
return;
}
if (res.code == 200) {
//examStatus 用户考试状态 0考试中 1考试完成 2未参与
if (that.isOnLoad && (res.data.examStatus == 1 || res.data.examStatus == 2)) {
//刚进来是考试完成和未参与,直接申请考试
that.isOnLoad = false;
that.applyExam();
return;
}
if (res.data.code == 401 || res.data.code == 403) {
//提示 提交结果失败 请再次提交
uni.showToast({
icon: "none",
title: "获取考试结果失败,请再次尝试提交",
});
return
that.isOnLoad = false;
if (res.data.examStatus == 1) {
that.isComplete = true;
that.examScore = res.data.examScore;
return;
}
if (res.data.code == 200) {
//examStatus 用户考试状态 0考试中 1考试完成 2未参与
if (res.data.data.examStatus == 2) {
that.applyExam();
return;
}
if (res.data.data.examStatus == 1) {
that.isComplete = true;
that.examScore = res.data.data.examScore;
return;
}
if (res.data.data.examStatus == 0) {
that.userExamId = res.data.data.id;
that.getNext();
if (res.data.examStatus == 0) {
that.userExamId = res.data.id;
let key = 'exma-' + this.examId;
let limitTime = uni.getStorageSync(key);
if(limitTime <= 0 || limitTime == ""){
let time = parseInt(
that.timeDefine["time-id-" + that.examId]
);
that.endTime = time;
that.currentTime = parseInt(time * 1000);
}else{
that.endTime = parseInt(limitTime);
that.currentTime = parseInt(limitTime * 1000);
}
} else {
uni.showToast({
icon: "none",
title: res.data.message,
});
that.getNext();
}
},
fail: (e) => {
uni.hideLoading();
} else {
uni.showToast({
icon: "none",
title: "获取考试信息失败",
title: res.data.message,
});
},
});
}
})
// .catch((err) => {
// uni.hideLoading();
// uni.showToast({
// icon: "none",
// title: err,
// });
// });
},
//申请考试
......@@ -264,57 +251,38 @@ export default {
});
let that = this;
uni.request({
url:
systemApiUrl +
"/wxh-worker-rest/rest/exam" +
"/serviceRule/" +
that.vuex_token +
"?examId=" +
this.examId,
method: "POST",
data: {
//examId:this.examId,
},
header: {
"Content-Type": "application/x-www-form-urlencoded",
},
success: (res) => {
uni.hideLoading();
if (res.statusCode == 401) {
this.gotoLogin();
return
}
if (res.data.code == 200) {
if (res.data.data.userExamId) {
that.userExamId = res.data.data.userExamId;
//申请完考试设置倒计时总时间
let time = parseInt(
this.timeDefine["time-id-" + this.examId]
);
this.endTime = time;
// let timestamp = new Date().getTime();
// this.endTime = timestamp + time * 1000;
this.currentTime = parseInt(time * 1000); //this.formatTimeToMini(timestamp);//endTime-currentTime再格式化时间显示
that.getNext();
}
} else {
uni.showToast({
icon: "none",
title: res.data.message,
});
let examId = this.examId;
this.$u.api.applyExam(examId)
.then((res) => {
uni.hideLoading();
if (res.code == 200) {
if (res.data.userExamId) {
that.userExamId = res.data.userExamId;
//申请完考试设置倒计时总时间
let time = parseInt(
this.timeDefine["time-id-" + this.examId]
);
this.endTime = time;
// let timestamp = new Date().getTime();
// this.endTime = timestamp + time * 1000;
this.currentTime = parseInt(time * 1000); //this.formatTimeToMini(timestamp);//endTime-currentTime再格式化时间显示
that.getNext();
}
},
fail: (e) => {
uni.hideLoading();
} else {
uni.showToast({
icon: "none",
title: "申请考试 失败",
title: res.data.message,
});
},
});
}
})
// .catch((err) => {
// uni.hideLoading();
// uni.showToast({
// icon: "none",
// title: "获取考试信息失败",
// });
// });
},
//获取下一题
......@@ -333,90 +301,64 @@ export default {
});
let that = this;
uni.request({
url:
systemApiUrl +
"/wxh-worker-rest/rest/exam" +
"/serviceRule/next/" +
that.vuex_token +
"?userExamId=" +
this.userExamId +
"&questionId=" +
questionId +
"&userAnswerIds=" +
(this.userAnswerIds || "9999") +
",", // 9999超时自动下一题
method: "POST",
header: {
"Content-Type": "application/x-www-form-urlencoded",
},
success: (res) => {
uni.hideLoading();
if (res.statusCode == 401) {
this.gotoLogin()
return;
this.$u.api.getNextQuestion(this.userExamId, questionId, this.userAnswerIds)
.then((res) => {
uni.hideLoading();
if (res.code == 200) {
that.currentItem = res.data;
that.progress = res.data.progress;
// if(this.isLoadQuestion){
// this.isLoadQuestion = false;
// if(!res.data.isQuestion){
// this.applyExam()
// return
// }
// let key = 'exma-' + this.examId;
// let limitTime = uni.getStorageSync(key);
// console.log(limitTime);
// // let limitTime = this.getLimitTime(that.progress);
// // console.log(limitTime);
// this.endTime = parseInt(limitTime);
// this.currentTime = parseInt(limitTime * 1000);
// }
if (res.data.isQuestion) {
let str = res.data.question.content;
var wz = str.indexOf(".");
let str1 = str.substring(wz + 1);
that.currentItem.question.content = str1.replace('*', '');
}
if(res.statusCode == 403){
uni.showToast({
icon: "none",
title: "获取考试结果失败,请再次尝试提交",
});
return
}
if (res.data.code == 200) {
that.currentItem = res.data.data;
that.progress = res.data.data.progress;
if(this.isLoadQuestion){
this.isLoadQuestion = false;
if(!res.data.data.isQuestion){
this.applyExam()
return
}
let key = 'exma-' + this.examId;
let limitTime = uni.getStorageSync(key);
console.log(limitTime);
// let limitTime = this.getLimitTime(that.progress);
// console.log(limitTime);
this.endTime = parseInt(limitTime);
this.currentTime = parseInt(limitTime * 1000);
}
if (res.data.data.isQuestion) {
let str = res.data.data.question.content;
var wz = str.indexOf(".");
let str1 = str.substring(wz + 1);
that.currentItem.question.content = str1.replace('*', '');
}
if (res.data.data.answerList) {
that.handleData();
// that.currentTime = 100
this.everyTime = getApp().globalData.questionTime; //每道题100s
that.isSelect = false;
clearTimeout(this.timer);
that.startCounting();
} else {
that.isSelect = true;
that.getUserExamInfo();
clearTimeout(this.timer);
this.isComplete = true;
//用来考完试判断跳转
this.examInfo = that.currentItem;
// that.bottomTitle = '完成考试,现在签约'
}
if (res.data.answerList) {
that.handleData();
// that.currentTime = 100
this.everyTime = getApp().globalData.questionTime; //每道题100s
that.isSelect = false;
clearTimeout(this.timer);
that.startCounting();
} else {
uni.showToast({
icon: "none",
title: res.data.message,
});
that.isSelect = true;
that.getUserExamInfo();
clearTimeout(this.timer);
this.isComplete = true;
//用来考完试判断跳转
this.examInfo = that.currentItem;
// that.bottomTitle = '完成考试,现在签约'
}
},
fail: (e) => {
uni.hideLoading();
// debugger
} else {
uni.showToast({
icon: "none",
title: "获取下一题 失败",
title: res.data.message,
});
},
});
}
})
// .catch((err) => {
// uni.hideLoading();
// uni.showToast({
// icon: "none",
// title: "获取考试信息失败",
// });
// });
},
getLimitTime(progress){
let arr = progress.split('/');
......
......@@ -39,9 +39,11 @@ export default {
onLoad(param) {
getApp().trackPage('学习开始考试页')
this.examId = param.examId;
this.getExamResult();
// this.getUserExamInfo();
},
onShow() {
this.getExamResult();
},
onUnload() {
uni.switchTab({
url: '/pages/index/learn'
......@@ -67,32 +69,29 @@ export default {
});
},
getExamResult() {
uni.request({
url:
process.uniEnv.systemUrl.apiUrl +
"/wxh-worker-rest/rest/exam/serviceRule/userExamInfo/" +
this.vuex_token +
"?examId=" +
this.examId,
method: "POST",
header: {
"Content-Type": "application/x-www-from-urlencoded",
},
success: (res) => {
uni.hideLoading();
if (res.data.code == 200) {
if (res.data.data.ruleDisc) {
var str = res.data.data.ruleDisc;
this.userExamId = res.data.data.id;
let strArr = str.split("(")[0].split(",");
this.title = strArr[0];
this.score = strArr[1];
this.time = strArr[2];
this.ruleDisc = strArr[3];
}
let examId = this.examId;
this.$u.api.getExamResult(examId)
.then((res) => {
uni.hideLoading();
if (res.code == 200) {
if (res.data.ruleDisc) {
var str = res.data.ruleDisc;
this.userExamId = res.data.id;
let strArr = str.split("(")[0].split(",");
this.title = strArr[0];
this.score = strArr[1];
this.time = strArr[2];
this.ruleDisc = strArr[3];
}
},
}
})
.catch((err) => {
uni.hideLoading();
uni.showToast({
icon: "none",
title: "获取考试信息失败",
});
});
},
},
......
......@@ -459,6 +459,7 @@
overflow: hidden;
background: #fff;
margin-top: 30rpx;
white-space: nowrap;
}
.scroll_box scroll-view {
......@@ -471,7 +472,7 @@
width: 280rpx;
height: 150rpx;
margin-right: 23rpx;
display: inline-grid;
display: inline-block;
background-color: #F4F5F7;
border-radius: 12rpx;
padding: 20rpx;
......
......@@ -45,15 +45,15 @@ export default {
bindTitle: '立即绑定',
bindPhone: '绑定手机',
bindTips: '首次登录的用户需绑定手机才可接单',
code: ''
code: '',
}
},
computed: {
logo() {
return this.qnPath + 'logo.png'
return util.imageCache(this, 'logo.png')
},
logo2() {
return this.qnPath + 'logo-2.png'
return util.imageCache(this, 'logo-2.png')
},
},
onLoad(e) {
......@@ -61,7 +61,7 @@ export default {
},
onShow() {
// 微信授权过用户信息,则无需重复授权
if (app.globalData.authUserInfo) {
if (this.vuex_auth_user && Object.keys(this.vuex_auth_user).length) {
this.needAuth = false
}
this.getCode()
......@@ -81,9 +81,7 @@ export default {
desc: '用于授权登录',
success: function (res) {
const userInfo = res.userInfo;
app.globalData.authUserInfo = userInfo
app.globalData.authUserInfo.nickName = app.globalData.authUserInfo.nickName || ''
app.globalData.authUserInfo.avatarUrl = app.globalData.authUserInfo.avatarUrl || ''
that.$u.vuex('vuex_auth_user', userInfo)
uni.showLoading({
title: '授权中..',
mask: true
......@@ -115,8 +113,8 @@ export default {
authLogin() {
var that = this
let params = {
nickname: app.globalData.authUserInfo.nickName,
avatar: app.globalData.authUserInfo.avatarUrl,
nickname: this.vuex_auth_user.nickName || '',
avatar: this.vuex_auth_user.avatarUrl || '',
}
login.appLogin().then(res => {
params.code = res.code
......@@ -124,7 +122,10 @@ export default {
}).then(res => {
uni.hideLoading();
if (res && res.code == 200 && res.data && res.data.token) {
app.setUserData(res.data, that)
login.setUserData(res.data, that)
app.track('auth_login', {mobile: res.data.mobile});
app.profileSet(that)
app.profileAppend(that)
that.goBackPage()
} else {
that.setLoginStatus()
......@@ -146,8 +147,8 @@ export default {
});
} else if(e.detail.encryptedData && e.detail.iv) {
let params = {
nickname: app.globalData.authUserInfo.nickName,
avatar: app.globalData.authUserInfo.avatarUrl,
nickname: this.vuex_auth_user.nickName || '',
avatar: this.vuex_auth_user.avatarUrl || '',
encryptedData: e.detail.encryptedData,
iv: e.detail.iv,
}
......@@ -160,6 +161,9 @@ export default {
uni.hideLoading()
if (res) {
app.setUserData(res.data, that)
app.track('signup_login', {mobile: res.data.mobile});
app.profileSet(that)
app.profileAppend(that)
app.getBaseInfo(that)
that.goBackPage()
} else {
......@@ -200,12 +204,14 @@ export default {
toLogin(params) {
login.appLogin().then(res => {
params.code = res.code
console.log("params3", params)
return login.signup(params);
}).then(res => {
uni.hideLoading()
if (res) {
app.setUserData(res.data, this)
login.setUserData(res.data, this)
app.track('signup_login', {mobile: res.data.mobile});
app.profileSet(this)
app.profileAppend(this)
app.getBaseInfo(this)
this.goBackPage()
} else {
......@@ -253,7 +259,7 @@ export default {
title: '登录页'
});
} else {
if(!app.globalData.authUserInfo) {
if(!this.vuex_auth_user || !Object.keys(this.vuex_auth_user).length) {
this.needAuth = true
uni.setNavigationBarTitle({
title: '授权页'
......
......@@ -56,6 +56,7 @@
<script>
let now = new Date(new Date().toLocaleDateString()).getTime();
import util from '@/utils/util.js'
import Statement from "@/components/mine/statement.vue"
export default {
components: {
......@@ -109,7 +110,7 @@
return process.uniEnv.qn_base_url
},
qianbaobeijing() {
return this.imageUrl + 'qianbaobeijing.png'
return util.imageCache(this, 'qianbaobeijing.png')
},
buttonStyle() {
return {
......
......@@ -44,6 +44,7 @@
<script>
let now = new Date(new Date().toLocaleDateString()).getTime();
import util from '@/utils/util.js'
import Settlement from "@/components/mine/settlement.vue"
const baseinfo = {totalAmount: 0, payableRecordExtendDtos: []}
export default {
......@@ -64,7 +65,7 @@
},
computed: {
liushuibeijingImage() {
return this.imageUrl + 'liushuibeijing.png'
return util.imageCache(this, 'liushuibeijing.png')
},
imageUrl() {
return process.uniEnv.qn_base_url
......@@ -73,7 +74,7 @@
return this.loading || this.info.payableRecordExtendDtos && this.info.payableRecordExtendDtos.length
},
banner() {
return this.imageUrl + 'receipt.png'
return util.imageCache(this, 'receipt.png')
},
},
onLoad() {
......
......@@ -45,6 +45,7 @@
<script>
let now = new Date(new Date().toLocaleDateString()).getTime();
const baseinfo = {expectedAmount: 0, settledAmount: 0, statementList: []}
import util from '@/utils/util.js'
import Statement from "@/components/mine/statement.vue"
export default {
components: {
......@@ -84,13 +85,13 @@
},
liushuibeijingImage() {
return this.imageUrl + 'liushuibeijing.png'
return util.imageCache(this, 'liushuibeijing.png')
},
imageUrl() {
return process.uniEnv.qn_base_url
},
banner() {
return this.imageUrl + 'receipt.png'
return util.imageCache(this, 'receipt.png')
},
hasInfo() {
return this.loading || this.data.statementList && this.data.statementList.length
......
......@@ -12,7 +12,7 @@ try {
}
// 需要永久存储,且下次APP启动需要取出的,在state中的变量名
let saveStateKeys = ['vuex_user', 'vuex_wx_uid', 'vuex_token', 'uploadTask'];
let saveStateKeys = ['vuex_user', 'vuex_wx_uid', 'vuex_token', 'vuex_cache', 'uploadTask'];
// 保存变量到本地存储中
const saveLifeData = function(key, value) {
......@@ -32,11 +32,14 @@ const store = new Vuex.Store({
// 如果上面从本地获取的lifeData对象下有对应的属性,就赋值给state中对应的变量
vuex_user: lifeData.vuex_user ? lifeData.vuex_user : {},
vuex_token: lifeData.vuex_token ? lifeData.vuex_token : '',
vuex_cache: lifeData.vuex_cache ? lifeData.vuex_cache : {},
vuex_version: '1.0.1',
vuex_config: {},
// 入驻信息
vuex_settled: null,
vuex_wx_uid: lifeData.vuex_wx_uid || 0,
// 授权用户信息
vuex_auth_user: {},
// 上传队列
uploadTask: lifeData.uploadTask ? lifeData.uploadTask : []
},
......
......@@ -116,11 +116,29 @@ function login(provider) {
});
}
/**
* 初始化用户信息
* @param {Object} userInfo 用户信息
* @param {Object} vm Vue对象实例
*/
function setUserData(userInfo, vm) {
if (userInfo && userInfo.token) {
// 如果已经登录则直接获取相关信息
vm.$u.vuex("vuex_token", userInfo.token);
vm.$u.vuex("vuex_user", userInfo);
vm.$u.vuex("vuex_wx_uid", userInfo.wxopenid);
} else {
vm.$u.vuex("vuex_token", "");
vm.$u.vuex("vuex_user", null);
vm.$u.vuex("vuex_wx_uid", "");
}
vm.$u.vuex("vuex_settled", null);
}
module.exports = {
appLogin: appLogin,
authorization: authorization,
signup: signup,
oauth: oauth
oauth: oauth,
setUserData,
}
\ No newline at end of file
var t = function(t) {
return (t = t.toString())[1] ? t : "0" + t;
import md5Libs from "uview-ui/libs/function/md5";
var t = function (t) {
return (t = t.toString())[1] ? t : "0" + t;
};
// const getToken = function(){
......@@ -18,44 +19,74 @@ var t = function(t) {
// }
// }
const getOpenid = function(){
const getOpenid = function () {
const app = getApp()
let openid = app && app.globalData && app.globalData.openid || ''
if(!openid){
if (!openid) {
openid = uni.getStorageSync('openid')
}
return openid
}
const setOpenid = function(openid){
const setOpenid = function (openid) {
const app = getApp()
uni.setStorageSync('openid',openid)
if(app && app.globalData){
uni.setStorageSync('openid', openid)
if (app && app.globalData) {
app.globalData.openid = openid
}
}
/**
* ====图片本地缓存====
* @param {Object} vm 当前vue实例
* @param {Object} src 图片地址
* @param {Object} host 图片前缀,默认使用qn_base_url
*/
const imageCache = function (vm, src, host) {
host = host || process.uniEnv.qn_base_url
let image_url = host + src
let image_name = md5Libs.md5(image_url)
var arr = Object.keys(vm.vuex_cache);
if (vm.vuex_cache && arr.length && arr.includes(image_name)) {
// call_back(vm.vuex_cache[image_name])
return vm.vuex_cache[image_name]
} else {
// 本地没有缓存 需要下载
uni.downloadFile({
url: image_url,
success: (res) => {
if (res.statusCode === 200) {
// call_back(res.tempFilePath)
vm.$u.vuex(`vuex_cache.${image_name}`, res.tempFilePath)
}
}
});
return image_url
}
}
module.exports = {
formatTime: function(n) {
var e = n.getFullYear(), r = n.getMonth() + 1, o = n.getDate(), i = n.getHours(), u = n.getMinutes(), a = n.getSeconds();
return [ e, r, o ].map(t).join("-") + " " + [ i, u, a ].map(t).join(":");
},
throttle: function(t, n) {
null != n && null != n || (n = 1500);
var e = null;
return function() {
var r = +new Date();
console.log(r + "," + e + "," + new Date()), (r - e > n || !e) && (t(), e = r);
};
},
formatLonLat: function(t, n) {
if (void 0 === t || "" == t) return "";
if (t += "", 0 == n) return parseFloat(t).toFixed(6);
var e = t.indexOf("."), r = e < 0 ? t : t.substring(0, e), o = 0, i = 0;
return e > 0 && (o = 60 * (o = "0" + t.substring(e)) + "", 2 == n ? (e = o.indexOf(".")) > 0 && (i = "0" + o.substring(e),
o = o.substring(0, e), e = (i = 60 * i + "").indexOf("."), i = i.substring(0, e + 4),
i = parseFloat(i).toFixed(0)) : 1 == n && (o = parseFloat(o).toFixed(6))), 2 == n ? r + "°" + o + "′" + i + "″" : 1 == n ? r + "°" + o + "′" : void 0;
},
formatTime: function (n) {
var e = n.getFullYear(), r = n.getMonth() + 1, o = n.getDate(), i = n.getHours(), u = n.getMinutes(), a = n.getSeconds();
return [e, r, o].map(t).join("-") + " " + [i, u, a].map(t).join(":");
},
throttle: function (t, n) {
null != n && null != n || (n = 1500);
var e = null;
return function () {
var r = +new Date();
console.log(r + "," + e + "," + new Date()), (r - e > n || !e) && (t(), e = r);
};
},
formatLonLat: function (t, n) {
if (void 0 === t || "" == t) return "";
if (t += "", 0 == n) return parseFloat(t).toFixed(6);
var e = t.indexOf("."), r = e < 0 ? t : t.substring(0, e), o = 0, i = 0;
return e > 0 && (o = 60 * (o = "0" + t.substring(e)) + "", 2 == n ? (e = o.indexOf(".")) > 0 && (i = "0" + o.substring(e),
o = o.substring(0, e), e = (i = 60 * i + "").indexOf("."), i = i.substring(0, e + 4),
i = parseFloat(i).toFixed(0)) : 1 == n && (o = parseFloat(o).toFixed(6))), 2 == n ? r + "°" + o + "′" + i + "″" : 1 == n ? r + "°" + o + "′" : void 0;
},
// getToken,
// setToken,
getOpenid,
setOpenid,
imageCache,
};
\ 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