相城应急答题

master
lion 1 year ago
parent c490e869c7
commit 1f55d6d248

@ -13,8 +13,8 @@
if (/code=/.test(link) || link.indexOf("code") > -1) {
let temp = decodeURIComponent((new RegExp('[?|&]' + 'code' + '=' + '([^&;]+?)(&|#|;|$)').exec(
link) || [, ''])[1].replace(/\+/g, '%20')) || null;
let gdz_lifeData = uni.getStorageSync('gdz_lifeData');
if (!gdz_lifeData.vuex_token) {
let xcyjdt_lifeData = uni.getStorageSync('xcyjdt_lifeData');
if (!xcyjdt_lifeData.vuex_token) {
const loginRes = await this.$u.api.login({
code: temp
});
@ -24,7 +24,7 @@
this.$u.vuex('vuex_user', userRes);
let url = location.href.split('#')[0];
let shareLink = "https://vr.langye.net/gdz/";
let shareLink = "https://vr.langye.net/h5xcyjdt/";
const shareRes = await this.$u.api.share({
url
});
@ -41,19 +41,19 @@
await new Promise((resolve) => {
jwx.ready(() => {
jwx.updateAppMessageShareData({
title: '“爱满星和”让孤独的世界充满温暖',
title: '人人讲安全、个个会应急',
link: shareLink,
desc: '守护“星”宝,爱不孤独!',
imgUrl: 'https://vr.langye.net/gdz/static/share.jpg',
desc: '——排查身边灾害隐患',
imgUrl: 'https://vr.langye.net/h5xcyjdt/static/share.jpg',
success: () => {
console.log('updateAppMessageShareData-success');
},
});
jwx.updateTimelineShareData({
title: '“爱满星和”让孤独的世界充满温暖',
desc: '守护“星”宝,爱不孤独!',
title: '人人讲安全、个个会应急',
desc: '——排查身边灾害隐患',
link: shareLink,
imgUrl: 'https://vr.langye.net/gdz/static/share.jpg',
imgUrl: 'https://vr.langye.net/h5xcyjdt/static/share.jpg',
success: () => {
console.log('updateTimelineShareData-success');
}
@ -66,7 +66,7 @@
this.$u.vuex('vuex_user', userRes);
let url = location.href.split('#')[0];
let shareLink = "https://vr.langye.net/gdz/";
let shareLink = "https://vr.langye.net/h5xcyjdt/";
const shareRes = await this.$u.api.share({
url
});
@ -83,19 +83,19 @@
await new Promise((resolve) => {
jwx.ready(() => {
jwx.updateAppMessageShareData({
title: '“爱满星和”让孤独的世界充满温暖',
title: '人人讲安全、个个会应急',
link: shareLink,
desc: '守护“星”宝,爱不孤独!',
imgUrl: 'https://vr.langye.net/gdz/static/share.jpg',
desc: '——排查身边灾害隐患',
imgUrl: 'https://vr.langye.net/h5xcyjdt/static/share.jpg',
success: () => {
console.log('updateAppMessageShareData-success');
},
});
jwx.updateTimelineShareData({
title: '“爱满星和”让孤独的世界充满温暖',
desc: '守护“星”宝,爱不孤独!',
title: '人人讲安全、个个会应急',
desc: '——排查身边灾害隐患',
link: shareLink,
imgUrl: 'https://vr.langye.net/gdz/static/share.jpg',
imgUrl: 'https://vr.langye.net/h5xcyjdt/static/share.jpg',
success: () => {
console.log('updateTimelineShareData-success');
}
@ -110,6 +110,7 @@
console.log(redirect);
window.location.href =
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appIdRes.appid}&redirect_uri=${redirect}&response_type=code&scope=snsapi_base#wechat_redirect`;
}
} catch (error) {
console.error('onLaunch 中出现错误:', error);
@ -120,7 +121,8 @@
},
onHide: function() {
console.log('App Hide')
}
}
}
</script>

@ -1,12 +1,14 @@
//api集合
let apiApp = {
login: '/api/mobile/user/wechat-login',
getAppId: '/api/mobile/user/wechat-login-url',
getAppId: '/api/mobile/user/wechat-login-url',
user: '/api/mobile/user/show',
share: '/api/mobile/user/wechat-share',
savePoster: '/api/mobile/vr/save-poster',
getPoster: '/api/mobile/vr/get-poster',
saveUser:'/api/mobile/user/save',
questions:'/api/mobile/quiz/get-questions',
saveQuestion:'/api/mobile/quiz/save-quiz-simple'
}
// 此处第二个参数vm就是我们在页面使用的this你可以通过vm获取vuex等操作
@ -18,7 +20,11 @@ const install = (Vue, vm) => {
let user = (params = {}) => vm.$u.get(apiApp.user, params);
let share = (params = {}) => vm.$u.get(apiApp.share, params);
let savePoster = (params = {}) => vm.$u.get(apiApp.savePoster, params);
let getPoster = (params = {}) => vm.$u.get(apiApp.getPoster, params)
let getPoster = (params = {}) => vm.$u.get(apiApp.getPoster, params)
let saveUser = (params = {}) => vm.$u.post(apiApp.saveUser, params)
let questions = (params = {}) => vm.$u.get(apiApp.questions, params)
let saveQuestion = (params = {}) => vm.$u.post(apiApp.saveQuestion, params)
// 将各个定义的接口名称统一放进对象挂载到vm.$u.api(因为vm就是this也即this.$u.api)下
vm.$u.api = {
login,
@ -26,7 +32,10 @@ const install = (Vue, vm) => {
getAppId,
share,
savePoster,
getPoster
getPoster,
saveUser,
questions,
saveQuestion
};
}

@ -21,10 +21,10 @@ const install = (Vue, vm) => {
// 请求拦截部分,如配置,每次请求前都会执行
Vue.prototype.$u.http.interceptor.request = (config) => {
console.log('config-http', config)
config.data.activity_tag = 'gdz'
config.data.activity_list_id = 17
let gdz_lifeData = uni.getStorageSync('gdz_lifeData')
let vuex_token = gdz_lifeData.vuex_token;
config.data.activity_tag = 'xcyjdt'
config.data.activity_list_id = 18
let xcyjdt_lifeData = uni.getStorageSync('xcyjdt_lifeData')
let vuex_token = xcyjdt_lifeData.vuex_token;
if (vuex_token || vm.vuex_token) {
config.header['Authorization'] = `Bearer ${vuex_token || vm.vuex_token}`;
}
@ -38,7 +38,7 @@ const install = (Vue, vm) => {
if (res.statusCode === 200) {
if (res.data.hasOwnProperty("errcode")) {
if (res.data?.errcode === 40001) {
uni.removeStorageSync('gdz_lifeData')
uni.removeStorageSync('xcyjdt_lifeData')
setTimeout(() => {
let origin = window.location.origin;
let pathname = window.location.pathname;

@ -12,7 +12,6 @@
<view class="slogan">守护成为有爱不孤独</view>
</view>
</view>
</view>
</view>
</view>

@ -1,6 +1,6 @@
{
"name" : "“爱满星和”让孤独的世界充满温暖",
"appid" : "__UNI__9CD555B",
"name" : "人人讲安全、个个会应急",
"appid" : "__UNI__1DBD598",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "100",
@ -71,12 +71,12 @@
"vueVersion" : "2",
"h5" : {
"router" : {
"base" : "gdz"
"base" : "h5xcyjdt"
},
"devServer" : {
"disableHostCheck" : true,
"https" : false
},
"title" : "“爱满星和”让孤独的世界充满温暖"
"title" : "人人讲安全、个个会应急"
}
}

@ -8,13 +8,33 @@
"style": {
"navigationStyle": "custom"
}
},{
"path": "pages/login/index",
"style": {
"navigationStyle": "custom"
}
},{
"path": "pages/me/me",
"style": {
"navigationStyle": "custom"
}
},{
"path": "pages/record/index",
"style": {
"navigationStyle": "custom"
}
},{
"path": "pages/answer/index",
"style": {
"navigationStyle": "custom"
}
}
],
"subPackages": [],
"preloadRule": {},
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "“爱满星和”让孤独的世界充满温暖",
"navigationBarTitleText": "人人讲安全、个个会应急",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
}

@ -0,0 +1,579 @@
<template>
<view class='wrap'>
<view class="top">
<view class='logintitle'>
<u-image style="margin:0 auto" :fade="false" :src="logintitle" width="702rpx" height="88rpx"></u-image>
<view style="color:#0095e5;text-align: center;font-size: 30rpx;margin: 0 auto;margin-top:20rpx;">
排查身边灾害隐患</view>
</view>
</view>
<view class="answerwrap">
<view class='answertop'>
<view>(答题{{questionIndex+1}}/5)</view>
<view>
<u-image style="display: inline-block;margin-right:5px" :fade="false" width="24rpx" height="24rpx"
:src='timeicon'></u-image>
{{minutes}}:{{seconds}}
</view>
</view>
<view>
<view class='answercenter'>
<view class='answertitle'>
<span
:class="[{'more':question_list[questionIndex]['type_name']==='多选题'}]">{{question_list[questionIndex]?question_list[questionIndex]['type_name']:''}}</span>
<text class="hasspan"
v-html="question_list[questionIndex]?replaceAtSymbolsWithSpan(question_list[questionIndex]['title']):''"></text>
</view>
<view class='answercheck'
v-for="(ans,ansindex) in question_list[questionIndex]?question_list[questionIndex].options:[]">
<view @click="chooseAnswer(ans,ansindex)"
:class="['answeritem',{'active':ans.flag},{'correct':ans.isanswer},{'wrong':ans.iswrong}]">
<span>{{answerNum[ansindex]}}</span>{{ans.title}}
<!-- {{ans.is_correct}}--- -->
<!-- :class="ans.flag?'answeritem active':'answeritem'" -->
</view>
</view>
</view>
</view>
<view class='answerbottom'>
<span></span>正确答案{{correctAnswer}}
</view>
</view>
<view class='submit'>
<u-button v-if="!answerSubmit" size="mini" :throttle-time="1000" shape="circle" type="default" :custom-style="parStyle"
@click="nextQue">下一题</u-button>
<u-button v-if="answerSubmit" size="mini" :throttle-time="1000" shape="circle" type="default" :custom-style="parStyle"
@click="nextQue">提交</u-button>
</view>
</view>
</template>
<script>
import {
isNull,
toast
} from "@/common/util.js"
export default {
data() {
return {
parStyle: {
'background': 'linear-gradient(to right, #2754a5, #2b83bb)',
'color': '#fff',
'font-size': '28rpx',
'padding': '20rpx 30rpx',
'margin-left': '15rpx',
'margin-top': '80rpx',
'width': '100%',
'height': '80rpx'
},
minutes: 0,
seconds: 0,
timer: null,
question_list: [],
questionIndex: 0,
answercount: 0, //
maxCount: 2,
answerNum: ["A", "B", "C", "D", "E", "F", "G", "H"],
myAnswer: [],
correctNum: 0, //
correctScore: 0, //
correctAnswer: '', //
answerSubmit: false, //
hasFlag: false, //
showAnswer: false,
timeicon: require('../../static/time.png'),
logintitle: require("../../static/logo3.png"),
isanswer: false, //
islock: false,
}
},
onShow() {
this.getUserInfo()
},
onLoad() {
let configs = uni.getStorageSync("activeConfig") ? uni.getStorageSync("activeConfig").config : []
let answertime = 15
configs.map(item => {
if (item.key == 'answer_time') {
answertime = parseInt(item.value)
}
})
this.getQuestion()
this.countdown(answertime, (minutes, seconds) => {
this.minutes = minutes.toString().padStart(2, '0')
this.seconds = seconds.toString().padStart(2, '0')
}, () => {
console.log("1--", this.islock)
if (!this.islock) {
this.submitQue()
}
});
},
onUnload() {
clearTimeout(this.timer)
},
methods: {
async getUserInfo() {
const res = await this.$u.api.user()
this.$u.vuex('vuex_user', res);
this.userInfo = res;
if (isNull(res.mobile)) {
uni.redirectTo({
url: '/pages/login/index'
})
}
},
async getQuestion() {
let that = this
const res = await this.$u.api.questions()
this.answercount = res.today_ask_count //
let data = res.questions
if (this.answercount) {
uni.redirectTo({
url: '/pages/me/me'
})
return
}
data.map(item => {
let type = 0
item.correctAnswer = []
item.options.map(i => {
i.flag = false
if (i.is_correct === 1) {
type++
item.correctAnswer.push(that.answerNum[i.myindex - 1])
}
})
item.type_name = type > 1 ? '多选题' : '单选题'
console.log("item.type_name",item.type_name)
})
console.log("data",data)
this.question_list = data
},
replaceAtSymbolsWithSpan(str) {
return str.replace(/@/g,
'<span style="display: inline-block;width:40px;border-bottom:1px solid #666;margin: 0 3px;margin-bottom: -2px;"></span>'
);
},
chooseAnswer(ans, ansindex) {
this.hasFlag = false
if (this.question_list[this.questionIndex]['type_name'] === '单选题') {
this.question_list[this.questionIndex]['options'].map(item => {
item.flag = false
})
ans.flag = !ans.flag
this.hasFlag = true
// ans.flag = !ans.flag
} else {
ans.flag = !ans.flag
this.question_list[this.questionIndex]['options'].map(item => {
if (item.flag == true) {
this.hasFlag = true
}
})
}
console.log("hasFlag", this.hasFlag)
},
submitQue() {
let that = this
if (this.myAnswer.length > 0) {
let count = 0
this.myAnswer.map(item => {
if (item.isCorrect === true) {
count++
}
})
this.correctNum = count
this.correctScore = (count / 10) * 100
} else {
this.correctScore = 0
}
this.islock = true
// this.showAnswer = true
console.log("3--", this.islock)
this.$u.api.saveQuestion({
score: this.correctScore,
answers: this.myAnswer
}).then(res=>{
clearTimeout(this.timer)
toast('答题已完成',1500,function(){
setTimeout(function(){
uni.redirectTo({
url:'/pages/me/me'
})
},1500)
})
})
},
nextQue() {
let that = this
// this.isanswer = false
if (this.isanswer) {
return
}
if (!this.hasFlag) {
toast("请先选择答案")
return
}
this.hasFlag = false
if (this.questionIndex > 4) {
this.answerSubmit = true
return
}
let ansid = []
let count = 0
this.question_list[this.questionIndex]['options'].map(item => {
if (item.flag === true) {
ansid.push(item.id)
}
if (!item.flag && item.is_correct === 1) {
count++
}
})
this.myAnswer.push({
question_id: this.question_list[this.questionIndex]['id'],
answer_ids: ansid.join("|"),
isCorrect: count > 0 ? false : true
})
this.correctAnswer = this.question_list[this.questionIndex]['correctAnswer'].join(',')
//
this.question_list[this.questionIndex]['options'].map(item => {
if (item.is_correct === 1) {
item.isanswer = true
} else if (item.flag == true && item.is_correct === 0) {
item.iswrong = true
}
})
this.isanswer = true
if (that.answerSubmit) {
that.submitQue()
return
}
setTimeout(function() {
that.correctAnswer = ''
that.isanswer = false
that.questionIndex++
if (that.questionIndex == 4) {
that.answerSubmit = true
// return
}
}, 1500)
},
countdown(duration, onTick, onEnd) {
let remainingTime = duration * 60;
const tick = () => {
if (remainingTime > -1) {
const minutes = Math.floor(remainingTime / 60);
const seconds = remainingTime % 60;
onTick(minutes, seconds);
remainingTime--;
this.timer = setTimeout(tick, 1000);
} else {
console.log("remainingTime", remainingTime)
console.log("2--", this.islock)
onEnd();
}
};
tick();
}
}
}
</script>
<style scoped lang="scss">
.wrap {
/* height: 100%; */
width: 100%;
height: 100vh;
width: 100vw;
background-image: url('../../static/bg.jpg');
background-size: 100% 100%;
background-repeat: no-repeat;
overflow: scroll;
}
.top {
width: 100%;
// height: 440rpx;
/* background-image: url('../../static/bgtop1.png'); */
background-size: 100% 100%;
background-repeat: no-repeat;
margin-bottom:30rpx;
// position: relative;
// top: 0;
// left: 0
}
.logintitle {
padding-top: 90rpx;
}
.bottom {
width: 100%;
height: 533rpx;
/* background-image: url('../../static/bgbottom.png'); */
background-size: 100% 100%;
background-repeat: no-repeat;
position: relative;
bottom: 0;
left: 0
}
.answerwrap {
position: relative;
z-index: 2;
width: 90%;
background-color: #f9f6f6;
border-radius: 40rpx;
margin: 0 auto;
box-shadow: 0px 0px 20px -10px #0095e5;
// margin-top: -40rpx;
}
.answertop {
display: flex;
justify-content: space-between;
background-color: red;
padding: 30rpx;
border-radius: 40rpx 40rpx 0 0;
border: 1px solid #0095e5;
background-color: #0095e5;
color: #fff;
border-bottom: none
}
.answercenter {}
.answertitle {
padding: 30rpx;
line-height: 1.8;
font-family: "宋体";
color: rgba(0, 0, 0, 0.8);
/* font-weight: bold; */
}
.answertitle span {
background-color: #2754a5;
display: inline-block;
padding: 0rpx 20rpx;
color: #fff;
margin-right: 10rpx;
border-radius: 10rpx;
font-weight: normal;
}
.answertitle span.more {
background-color: cadetblue;
}
.borderb {
display: inline-block;
width: 10rpx;
border-bottom: 1px solid #666;
}
.answercheck {
padding: 30rpx;
padding-top: 0rpx;
}
.answeritem {
padding: 20rpx;
background-color: #fff;
border: 4rpx solid #fff;
border-radius: 20rpx;
color: #666666;
}
.answeritem.active,
.answeritem.wrong {
border: 4rpx solid #0095e5;
}
.answeritem.correct {
border: 4rpx solid green;
}
.answeritem span {
display: inline-block;
width: 40rpx;
height: 40rpx;
border: 2px solid #999;
color: #999;
text-align: center;
line-height: 40rpx;
border-radius: 10rpx;
margin-right: 10rpx
}
.answeritem.active span,
.answeritem.wrong span {
border: 2px solid #0095e5;
background-color: #0095e5;
color: #fff;
}
.answeritem.correct span {
border: 2px solid green;
background-color: green;
color: #fff;
}
.answerbottom {
padding: 30rpx;
padding-top: 10rpx;
padding-bottom: 40rpx;
}
.answerbottom span {
display: inline-block;
width: 10rpx;
height: 50rpx;
border-radius: 10rpx;
background-color: green;
vertical-align: middle;
margin-right: 20rpx
}
.submit {
width: 50%;
margin: 30px auto;
// margin-bottom: -250rpx;
position: relative;
z-index: 9
}
.answertip {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
/* padding-top:397rpx;
padding-bottom:300rpx; */
z-index: 9;
}
.answertipitem {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 77%;
}
.answrap {
/* background: url(../../static/answertipbg1.png); */
width: 483rpx;
height: 563rpx;
background-size: 100% 100%;
font-size: 28rpx;
width: 100%;
}
.answrap100 {
/* background: url(../../static/answertipbg.png); */
height: 612rpx;
background-size: 100% 100%;
width: 100%;
}
.ansscore {
padding-top: 120rpx;
text-align: center;
}
.ansflag {
/* background: url(../../static/answer100flag.png); */
width: 119%;
height: 164rpx;
background-size: 100% 100%;
position: absolute;
top: 240rpx;
left: -56rpx;
}
.answrap100 .ansflag {
top: 290rpx;
}
.ansicon {
position: absolute;
left: 235rpx;
top: -20rpx;
}
.ansicon80 {
position: absolute;
left: 165rpx;
top: -80rpx;
}
/* .answer100>view:first-child{
margin-top: 236rpx;
margin-left: 210rpx;
} */
.answerBtn {
/* margin-top: 236rpx;
margin-left: 210rpx; */
/* display:flex;
margin-top:100rpx;
margin-left:80rpx */
text-align: center;
/* margin-top: 120rpx; */
position: absolute;
top: 355rpx;
left: 0rpx;
width: 100%;
}
.answrap100 .answerBtn {
top: 410rpx;
}
.answerBtn view {
box-shadow: 1rpx 7rpx 18rpx 0rpx #2754a5;
color: #333;
padding: 16rpx 60rpx;
margin: 10rpx;
font-size: 28rpx;
border-radius: 10rpx;
display: inline-block;
}
.answerBtn view:last-child {
color: #fff;
background: linear-gradient(90deg, to right, #2754a5, #2b83bb);
}
.answertip span.ansfont {
color: #0095e5;
font-size: 90rpx;
}
.answer80 {
/* background: url(../../static/answer80.png); */
width: 483rpx;
height: 641rpx;
background-size: 100% 100%;
}
</style>

@ -1,129 +1,175 @@
<template>
<view class="container">
<video v-if="showVideo" :controls="false" class="full-video" :src="videoSrc" autoplay @ended="onVideoEnd"
object-fit="cover"></video>
<swiper class="swiper" :disable-touch="!canSwipe" :current="currentIndex" :autoplay="false" @change="changeCurrent"
:vertical="true">
<swiper-item class="swiper-item" v-for="(Component, index) in componentList">
<view class="scrollContent">
<!-- 循环渲染子组件 -->
<component @scrollTop="scrollTop" @scrollBottom="scrollBottom" @playVideo="playVideo"
:is="Component" :key="index"></component>
</view>
</swiper-item>
</swiper>
<view class="wrap">
<image src="@/static/bg.jpg" class="bkg" alt="" />
<view class="main">
<view class="main-wrap">
<image src="@/static/index_logo.png" class="logo" alt="" />
<image src="@/static/index_words.png" class="words" alt="" />
<image src="@/static/index_words2.png" class="words2" alt="" />
<image src="@/static/index_words3.png" class="words3" alt="" />
<view class="btns" @click="towhere">
<text>点击进入答题</text>
<u-icon name="arrow-right" color="#fff"></u-icon>
</view>
</view>
<image src="@/static/logo2.png" class="logo2" alt="" />
</view>
<view class="support">
技术支撑江苏有线苏州分公司
</view>
</view>
</template>
<script>
<script>
import {isNull} from "@/common/util.js"
export default {
data() {
return {
componentList: [],
currentIndex: 0,
showVideo: false,
videoSrc: '/static/video.mp4',
context: null,
audioSrc: '/static/audio.mp3',
playStatus: false,
canSwipe: false
isEnd: false, //
userInfo: {}
}
},
async onLoad() {
onLoad() {
// this.play2(0)
// this.getUserInfo()
this.getConfig()
},
mounted() {
// 使 require.context
const componentContext = require.context('@/components/mypage', false, /\.vue$/);
componentContext.keys().forEach(key => {
const component = componentContext(key).default;
this.componentList.push(component);
});
//
this.context = uni.createInnerAudioContext();
this.context.src = this.audioSrc;
this.context.loop = true
},
beforeDestroy() {},
methods: {
playVideo(e) {
if (e) {
this.showVideo = true
this.currentIndex = 1
this.canSwipe = true
if (!this.playStatus) {
this.context.play()
this.playStatus = true
async getConfig() {
// /
const res = await this.$u.api.getAppId()
this.isEnd = this.isCurrentTimeBetween(res.start_time, res.end_time)
let config = res.config
config.map(item => {
if (item.key === 'active_tip') {
uni.setStorageSync('active_tip', item.value)
}
}
},
touchMove1() {
if (!this.canSwipe) {
event.preventDefault();
}
},
onEnded() { //
this.context.onEnded(() => {
this.playStatus = false
this.context.play()
})
uni.setStorageSync('activeConfig', res)
uni.setStorageSync('isEnd', this.isEnd)
},
onVideoEnd() {
this.showVideo = false
},
changeCurrent(e) {
this.currentIndex = e.detail.current
isCurrentTimeBetween(startTime, endTime) {
let that = this
const now = that.$moment().valueOf()
const start = that.$moment(startTime).valueOf();
const end = that.$moment(endTime).valueOf();
console.log("123", now, start, end)
return now >= start && now <= end;
},
async getUserInfo() {
const res = await this.$u.api.user()
this.$u.vuex('vuex_user', res);
this.userInfo = res;
if (isNull(res.mobile)) {
uni.redirectTo({
url: '/pages/login/index'
})
}
},
},
async towhere() {
await this.getUserInfo()
let url = '/pages/me/me'
if (isNull(this.userInfo.mobile)) {
url = '/pages/login/index'
}
console.log("url", url)
uni.navigateTo({
url: url
})
}
}
}
</script>
<style lang="scss">
.container {
height: 100vh;
width: 100vw;
position: relative;
.full-video {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 999;
}
/* 隐藏视频播放条 */
video::-webkit-media-controls {
display: none !important;
<style scoped lang="scss">
.wrap {
width: 100vw;
height: 100vh;
position: relative;
font-size: 0;
.bkg {
width: 100vw;
height: 100vh;
position: absolute;
top: 0;
left: 0;
}
video::-webkit-media-controls-enclosure {
display: none !important;
.main{
width: 100vw;
height: 100vh;
overflow: scroll;
position: relative;
z-index:9;
&-wrap{
position: relative;
z-index:8;
margin-top:100rpx;
&>image{
margin:0 auto;
display: block;
margin-top:40rpx;
}
.logo{
width:293rpx;
height:294rpx;
}
.words{
width:617rpx;
height:279rpx;
}
.words2{
width:750rpx;
height:80rpx;
}
.words3{
width:537rpx;
height:34rpx;
}
.btns{
width:617rpx;
height:100rpx;
padding:0 40rpx;
border-radius: 80rpx;
background-color: #95a1b1;
color:#fff;
margin:0 auto;
margin-top:50rpx;
font-size: 36rpx;
line-height: 100rpx;
text-align: center;
position: relative;
opacity: 0.9;
.u-icon{
position: absolute;
right:40rpx;
top:50%;
transform: translateY(-50%);
}
}
}
.logo2{
width:359rpx;
height:332rpx;
position: absolute;
bottom:0;
left:0
}
}
.support {
position: absolute;
bottom: 10rpx;
width: 100%;
font-size: 24rpx;
color: #888;
font-family: '宋体';
opacity: 1;
text-align: center;
z-index:9
}
video::-webkit-media-controls-panel {
display: none !important;
}
.swiper {
height: 100vh;
width: 100vw;
.swiper-item {
height: 100%;
width: 100%;
}
.content {
width: 100%;
min-height: 100%;
}
}
}
</style>

@ -0,0 +1,317 @@
<template>
<view class='wrap'>
<view class="formwrap">
<view class='logintitle'>
<image src="@/static/index_logo.png" class="logo" alt="" />
<image src="@/static/logo3.png" class="words" alt="" />
<view class="subtitle">
排查身边灾害隐患</view>
<view class='logintitletext'>
<span>答题时间</span>
<span>{{startTime}}{{endTime}}</span>
</view>
</view>
<view class="loginform">
<view>
<u-input :placeholderStyle="'color:#999;font-size:30rpx'"
:custom-style="{'background':'#fff','padding':'15rpx 30rpx','border-radius':'80rpx'}"
v-model="form.name" placeholder="请输入姓名" :border="false" shape="circle" clearable></u-input>
</view>
<view>
<u-input :placeholderStyle="'color:#999;font-size:30rpx'"
:custom-style="{'background':'#fff','padding':'15rpx 30rpx','border-radius':'80rpx'}"
v-model="form.mobile" placeholder="请输入手机号" :border="false" shape="circle" clearable></u-input>
</view>
</view>
<view class="loginbtn">
<u-button size="mini" :throttle-time="2000" shape="circle" type="default" :custom-style="parStyle"
@click="submit">提交</u-button>
<image src="@/static/logintip.png" class="logintips" alt="" @click="showtips=true" />
</view>
</view>
<!-- 活动须知 -->
<u-popup v-model="showtips" mode="center">
<view class="tipwrap">
<view class="tiptitle">
活动须知
</view>
<view class="tipcenter">
<view>
<view v-html="active_tip"></view>
</view>
</view>
<view class="answerBtn">
<view @click="showtips=false"></view>
</view>
</view>
</u-popup>
</view>
</template>
<script>
import {
isNull,toast
} from "@/common/util.js"
export default {
data() {
return {
parStyle: {
'background': 'linear-gradient(to right, #2754a5, #2b83bb)',
'color': '#fff',
'font-size': '28rpx',
'padding': '20rpx 30rpx',
'margin-left': '15rpx',
'margin-top': '80rpx',
'width': '100%',
'height': '80rpx'
},
tip: '',
form: {
name: '',
mobile: '',
},
isEnd: true,
showtips: false,
tiptitle: '',
active_tip: '',
maskHeight: 0,
windowHeight: 0,
activeConfig: {},
startTime: '',
endTime: '',
}
},
onShow() {
let user = this.vuex_user
if (user) {
if (!isNull(user.mobile)) {
uni.redirectTo({
url: '/pages/me/me'
})
}
}
},
onLoad() {
this.isEnd = uni.getStorageSync('isEnd')
this.active_tip = uni.getStorageSync('active_tip')
console.log("uni.getStorageSync('active_tip')",uni.getStorageSync('active_tip'))
this.activeConfig = uni.getStorageSync('activeConfig')
if (this.activeConfig.start_time) {
this.startTime = this.formatDateToMonthDay(this.activeConfig.start_time)
}
if (this.activeConfig.end_time) {
this.endTime = this.formatDateToMonthDay(this.activeConfig.end_time)
}
},
methods: {
formatDateToMonthDay(dateString) {
const month = this.$moment(dateString).format('MM')
const day = this.$moment(dateString).format('DD')
return `${month}${day}`;
},
openTips() {
const query = uni.createSelectorQuery().in(this);
query.select('.wrap').boundingClientRect(({
height
}) => {
console.log("height", height);
if (this.windowHeight > height) {
this.maskHeight = this.windowHeight;
} else {
this.maskHeight = height;
}
}).exec();
this.showtips = true
// this.showSucess = true
},
isOnlyChinese(str) {
const chineseRegex = /^[\u4e00-\u9fa5]+$/;
return chineseRegex.test(str);
},
submit() {
if (!this.isEnd) {
toast("活动已结束")
return
}
if (isNull(this.form.name) || isNull(this.form.mobile)) {
toast("请填写所有信息")
return
}
if (!this.isOnlyChinese(this.form.name)) {
toast("请输入中文姓名")
return
}
if (!isNull(this.form.mobile) && !uni.$u.test.mobile(this.form.mobile)) {
toast("请输入正确的手机号")
return
}
this.$u.api.saveUser({
...this.form
}).then(res => {
this.$u.vuex('vuex_user', res);
uni.showToast({
title: '注册成功',
icon: 'none',
duration: 1500,
success() {
uni.redirectTo({
url: '/pages/me/me'
})
}
})
})
}
}
}
</script>
<style scoped lang="scss">
.wrap {
height: 100vh;
width: 100vw;
background-image: url('../../static/bg.jpg');
background-size: 100% 100%;
background-repeat: no-repeat;
overflow: scroll;
.formwrap {
width: 90%;
padding-top: 100rpx;
margin: 0 auto;
padding-bottom: 120rpx
}
.logintitle {
.logo {
width: 293rpx;
height: 294rpx;
margin: 0 auto;
display: block;
}
.words {
width: 702rpx;
height: 88rpx;
margin: 0 auto;
display: block;
}
.subtitle {
color: #2754a5;
text-align: center;
font-size: 28rpx;
margin: 0 auto;
margin-top: 20rpx;
}
.logintitletext {
margin-top: 40rpx;
text-align: center;
}
.logintitletext span {
font-size: 28rpx;
color: #999999;
border-radius: 0 60rpx 60rpx 0;
background-color: #fff;
padding: 10rpx 20rpx
}
.logintitletext span:first-child {
background-color: #0095e5;
color: #fff;
border-radius: 60rpx 0 0 60rpx;
}
}
.loginbtn {
padding: 20rpx 30rpx;
padding-top: 0;
.logintips {
width: 141rpx;
height: 28rpx;
margin: 20rpx auto;
display: block;
}
}
}
.tipwrap {
width: 650rpx;
// background: #fff;
font-size: 28rpx;
padding:30rpx;
.tiptitle {
width: 100%;
text-align: center;
font-size: 36rpx;
}
.tipcenter {
background-color: #fff;
min-height: 200rpx;
line-height: 1.8;
width: 100%;
box-sizing: content-box;
margin-top: -5rpx;
&>view {
padding: 20px;
padding-bottom: 0;
}
}
.answerBtn {
text-align: center;
padding-bottom: 40rpx;
background-color: #fff;
width: 100%;
text-align: center;
margin-top: -5rpx;
padding-top: 40rpx;
position: relative;
top: 0;
left: 0;
&>view {
box-shadow: 1rpx 7rpx 18rpx 0rpx #2754a5;
color: #333;
padding: 16rpx 70rpx;
margin: 10rpx;
font-size: 28rpx;
border-radius: 10rpx;
display: inline-block;
}
&>view:last-child {
color: #fff;
background: linear-gradient(90deg, #2754a5, #2b83bb);
}
}
}
.loginform {
padding: 30rpx 20rpx;
margin-top: 30rpx
}
.loginform>view {
margin-bottom: 40rpx;
}
</style>

@ -0,0 +1,427 @@
<template>
<view class="wrap">
<view class="container">
<view class="user-info">
<view class="user-info-avatar">
<img class="avatar" :src="userInfo.headimgurl ? userInfo.headimgurl : logo" alt="">
</view>
<view class="user-info__text">
<view class="name">
{{ userInfo.name || 'xx' }}
</view>
<view class="club">
{{ userInfo.mobile ? userInfo.mobile : '' }}
</view>
</view>
</view>
<view class="panel1">
<view class="left">
<view class="num">{{answercount}}</view>
<view class="text">已答次数</view>
</view>
<view class="right">
<view class="num">{{ userInfo.quiz_total_score || 0 }}</view>
<view class="text">累计得分</view>
</view>
</view>
<view class="panel2">
<view class="top">
<view @click="toanswer">
<u-icon name="edit-pen-fill" color="#de242f" size="60rpx"></u-icon>
<view class="text">参与答题</view>
</view>
<view @click='torecord'>
<u-icon name="calendar" color="#de242f" size="60rpx"></u-icon>
<view class="text">答题记录</view>
</view>
</view>
<view class="bottom">
<view class="row" @click="showtips=true">
<u-icon name="info-circle-fill" color="#de242f" size="40rpx"></u-icon>
<view class="text">活动须知</view>
<u-icon name="arrow-right" color="#333" size="38rpx"></u-icon>
</view>
<view class="row">
<u-icon name="gift-fill" :color="open_win?'#de242f':'#999999'" size="40rpx"></u-icon>
<view class="text">中奖情况</view>
<text v-if="open_win" @click='openWins'>查看</text>
<text v-else></text>
</view>
</view>
</view>
</view>
<!-- 获奖 -->
<u-popup v-model="showwin" mode="center">
<view class="tipwrap">
<view class="tiptitle">
获奖通知
</view>
<view class="tipcenter">
<view>{{userInfo.name?userInfo.name:''}}</view>
<view>请保持通话畅通工作人员会与您联系</view>
</view>
<view class="answerBtn">
<view @click="showwin=false"></view>
</view>
</view>
</u-popup>
<!-- 活动须知 -->
<u-popup v-model="showtips" mode="center">
<view class="tipwrap">
<view class="tiptitle">
活动须知
</view>
<view class="tipcenter">
<view>
<view v-html="active_tip"></view>
</view>
</view>
<view class="answerBtn">
<view @click="showtips=false"></view>
</view>
</view>
</u-popup>
</view>
</template>
<script>
import {
isNull,
toast
} from "@/common/util.js"
export default {
data() {
return {
logo:require('@/static/index_logo.png'),
userInfo: {},
answercount: 0,
showRecord: false,
showNowin: false,
showwin: false,
showtips: false,
winimg: '',
tiptitle: '',
isEnd: true,
active_tip: '',
maxCount: 2,
open_win: false,
today_ask_count: 0
};
},
methods: {
openWins() {
if (this.userInfo.pid === 1) {
this.showwin = true
} else {
toast('很遗憾,您未得奖')
}
},
toanswer() {
if (!this.isEnd) {
toast("活动已结束")
return
}
if (this.today_ask_count) {
toast(`您的今日答题次数已用完`)
return
} else {
uni.navigateTo({
url: '/pages/answer/index'
})
}
},
torecord() {
uni.navigateTo({
url: '/pages/record/index'
})
},
async getUserInfo() {
const res = await this.$u.api.user()
this.$u.vuex('vuex_user', res);
this.userInfo = res;
if (isNull(res.mobile)) {
uni.redirectTo({
url: '/pages/login/index'
})
}
},
async getQuestion() {
const res = await this.$u.api.questions()
this.today_ask_count = res.today_ask_count
this.answercount = res.ask?res.ask.length:0
},
},
onLoad() {
this.getUserInfo()
this.getQuestion()
this.isEnd = uni.getStorageSync('isEnd')
this.active_tip = uni.getStorageSync('active_tip')
let configs = uni.getStorageSync("activeConfig") ? uni.getStorageSync("activeConfig").config : []
configs.map(item => {
if (item.key == 'open_win') {
this.open_win = item.value == 1 ? true : false
}
})
},
}
</script>
<style lang="scss" scoped>
.wrap {
height: 100vh;
width: 100vw;
background-image: url('../../static/bg.jpg');
background-size: 100% 100%;
background-repeat: no-repeat;
overflow: scroll;
}
.tipwrap {
width: 650rpx;
// background: #fff;
font-size: 28rpx;
padding:30rpx;
.tiptitle {
width: 100%;
text-align: center;
font-size: 36rpx;
}
.tipcenter {
background-color: #fff;
min-height: 200rpx;
line-height: 1.8;
width: 100%;
box-sizing: content-box;
margin-top: -5rpx;
&>view {
padding: 20px;
padding-bottom: 0;
}
}
.answerBtn {
text-align: center;
padding-bottom: 40rpx;
background-color: #fff;
width: 100%;
text-align: center;
margin-top: -5rpx;
padding-top: 40rpx;
position: relative;
top: 0;
left: 0;
&>view {
box-shadow: 1rpx 7rpx 18rpx 0rpx #2754a5;
color: #333;
padding: 16rpx 70rpx;
margin: 10rpx;
font-size: 28rpx;
border-radius: 10rpx;
display: inline-block;
}
&>view:last-child {
color: #fff;
background: linear-gradient(90deg, #2754a5, #2b83bb);
}
}
}
.container {
position: relative;
z-index: 1;
.user-info {
display: flex;
align-items: center;
padding: 82rpx 0 0 54rpx;
.user-info-avatar {
width: 121rpx;
height: 121rpx;
border-radius: 100%;
// object-fit: contain;
// border: 1rpx solid #fff;
// box-sizing: border-box;
}
.avatar {
width: 121rpx;
height: 121rpx;
border-radius: 100%;
// object-fit: contain;
// border: 1rpx solid #fff;
// box-sizing: border-box;
}
&__text {
color: #fff;
margin-left: 32rpx;
.name {
font-size: 36rpx;
font-weight: 500;
word-break: keep-all;
line-height: 42rpx;
}
.club {
font-size: 26rpx;
font-weight: 400;
margin-top: 13rpx;
}
}
}
@mixin panel {
width: 658rpx;
background: #fff;
box-sizing: border-box;
border-radius: 40rpx;
filter: drop-shadow(0 0 7.5px rgba(226, 54, 50, 0.1));
margin: auto;
.num {
font-size: 52rpx;
text-transform: uppercase;
color: #ff0000;
font-weight: bold;
}
.text {
font-size: 28rpx;
text-transform: uppercase;
color: #666666;
}
}
.panel1 {
@include panel;
height: 164rpx;
display: flex;
align-items: center;
margin: 73rpx auto 0 auto;
&>view {
flex: 1;
text-align: center;
&:nth-child(1) {
position: relative;
&::after {
content: "";
height: 91rpx;
width: 2rpx;
background: #989898;
opacity: 0.302;
transform: translateY(-50%);
position: absolute;
right: 0;
top: 50%;
}
}
}
}
.panel2 {
@include panel;
height: 689rpx;
margin-top: 30rpx;
padding: 0 46rpx 0 42rpx;
.top {
display: flex;
align-items: center;
padding-top: 50rpx;
padding-bottom: 46rpx;
position: relative;
&>view {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
img {
height: 60rpx;
object-fit: contain;
margin-bottom: 24rpx;
}
}
&::after {
content: "";
background: #989898;
opacity: 0.302;
height: 2rpx;
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
}
.bottom {
.row {
display: flex;
align-items: center;
padding: 34rpx 4rpx 34rpx 23rpx;
position: relative;
&::after {
content: "";
height: 2rpx;
background: #989898;
opacity: 0.302;
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
.text {
flex: 1;
padding-left: 20rpx;
}
text {
font-size: 28rpx;
text-transform: uppercase;
color: #666666;
}
}
}
}
}
</style>

@ -0,0 +1,257 @@
<template>
<view class="wrap">
<view class="container">
<view class="user-info">
<view class="user-info-avatar">
<img class="avatar" :src="userInfo.headimgurl ? userInfo.headimgurl : logo" alt="">
</view>
<view class="user-info__text">
<view class="name">
{{ userInfo.name || 'xx' }}
</view>
<view class="club">
{{ userInfo.mobile ? userInfo.mobile : '' }}
</view>
</view>
</view>
<view class="panel1">
<view class="left">
<view class="num">{{answercount}}</view>
<view class="text">已答次数</view>
</view>
<view class="right">
<view class="num">{{ userInfo.quiz_total_score || 0 }}</view>
<view class="text">累计得分</view>
</view>
</view>
<view style="padding-bottom:40rpx">
<view class="panel1 panel2" v-for="(item,index) in askList">
<view class="left">
<view class="num">
{{item.score}}<span></span>
</view>
</view>
<view class="right">
<view class="num">{{numberToChinese(index+1)}}次答题</view>
<view class="text">{{item.created_at?item.created_at.substring(0,16):''}}</view>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
import {
isNull,
toast
} from "@/common/util.js"
export default {
data() {
return {
logo:require('@/static/index_logo.png'),
userInfo: {},
answercount: 0,
askList: [],
countList: ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十"],
};
},
methods: {
async getUserInfo() {
const res = await this.$u.api.user()
this.$u.vuex('vuex_user', res);
this.userInfo = res;
if (isNull(res.mobile)) {
uni.redirectTo({
url: '/pages/login/index'
})
}
},
async getQuestion() {
let that = this
const res = await this.$u.api.questions()
that.answercount = res.ask.length
that.askList = res.ask
},
numberToChinese(num) {
const chineseDigits = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
const chineseUnits = ['', '十', '百', '千', '万', '亿'];
const numStr = num.toString();
const numLength = numStr.length;
let result = '';
for (let i = 0; i < numLength; i++) {
const digit = parseInt(numStr[i]);
const unit = chineseUnits[numLength - i - 1];
if (digit !== 0) {
result += chineseDigits[digit] + unit;
} else {
if (unit === '十' || unit === '百' || unit === '千') {
result += chineseDigits[digit];
}
}
}
return result;
}
},
onLoad() {
this.getQuestion()
},
onShow() {
this.getUserInfo()
},
}
</script>
<style lang="scss" scoped>
.wrap {
height: 100vh;
width: 100vw;
background-image: url('../../static/bg.jpg');
background-size: 100% 100%;
background-repeat: no-repeat;
overflow: scroll;
}
.container {
position: relative;
z-index: 1;
.user-info {
display: flex;
align-items: center;
padding: 82rpx 0 0 54rpx;
.user-info-avatar {
width: 121rpx;
height: 121rpx;
border-radius: 100%;
// object-fit: contain;
// border: 1rpx solid #fff;
// box-sizing: border-box;
}
.avatar {
width: 121rpx;
height: 121rpx;
border-radius: 100%;
}
&__text {
color: #fff;
margin-left: 32rpx;
.name {
font-size: 36rpx;
font-weight: 500;
word-break: keep-all;
line-height: 42rpx;
}
.club {
font-size: 24rpx;
font-weight: 400;
margin-top: 13rpx;
}
}
}
@mixin panel {
width: 658rpx;
background: #fff;
box-sizing: border-box;
border-radius: 40rpx;
filter: drop-shadow(0 0 7.5px rgba(226, 54, 50, 0.1));
margin: auto;
.num {
font-size: 52rpx;
text-transform: uppercase;
color: #ff0000;
font-weight: bold;
}
.text {
font-size: 28rpx;
text-transform: uppercase;
color: #666666;
}
}
.panel1 {
@include panel;
height: 164rpx;
display: flex;
align-items: center;
margin: 73rpx auto 0 auto;
&>view {
flex: 1;
text-align: center;
&:nth-child(1) {
position: relative;
&::after {
content: "";
height: 91rpx;
width: 2rpx;
background: #989898;
opacity: 0.302;
transform: translateY(-50%);
position: absolute;
right: 0;
top: 50%;
}
}
}
}
.panel2 {
margin: 40rpx auto;
.left {
flex: none;
width: 30%;
.num {
span {
font-size: 28rpx;
color: #666;
font-weight: normal;
}
}
}
.right {
text-align: left;
padding: 0 60rpx;
.num {
font-size: 40rpx;
color: #333;
}
}
}
}
</style>

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 950 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 831 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 895 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 790 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 961 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 302 KiB

After

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 627 B

Binary file not shown.

@ -2,11 +2,11 @@ import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
let gdz_lifeData = {};
let xcyjdt_lifeData = {};
try{
// 尝试获取本地是否存在gdz_lifeData变量第一次启动APP时是不存在的
gdz_lifeData = uni.getStorageSync('gdz_lifeData');
// 尝试获取本地是否存在xcyjdt_lifeData变量第一次启动APP时是不存在的
xcyjdt_lifeData = uni.getStorageSync('xcyjdt_lifeData');
}catch(e){
}
@ -15,26 +15,26 @@ try{
let saveStateKeys = ['vuex_user', 'vuex_token','vuex_share'];
// 保存变量到本地存储中
const savegdz_LifeData = function(key, value){
const savexcyjdt_LifeData = function(key, value){
// 判断变量名是否在需要存储的数组中
if(saveStateKeys.indexOf(key) != -1) {
// 获取本地存储的gdz_lifeData对象将变量添加到对象中
let tmp = uni.getStorageSync('gdz_lifeData');
// 第一次打开APP不存在gdz_lifeData变量故放一个{}空对象
// 获取本地存储的xcyjdt_lifeData对象将变量添加到对象中
let tmp = uni.getStorageSync('xcyjdt_lifeData');
// 第一次打开APP不存在xcyjdt_lifeData变量故放一个{}空对象
tmp = tmp ? tmp : {};
tmp[key] = value;
// 执行这一步后,所有需要存储的变量,都挂载在本地的gdz_lifeData对象中
uni.setStorageSync('gdz_lifeData', tmp);
// 执行这一步后,所有需要存储的变量,都挂载在本地的xcyjdt_lifeData对象中
uni.setStorageSync('xcyjdt_lifeData', tmp);
}
}
const store = new Vuex.Store({
// 下面这些值仅为示例,使用过程中请删除
state: {
// 如果上面从本地获取的gdz_lifeData对象下有对应的属性就赋值给state中对应的变量
// 如果上面从本地获取的xcyjdt_lifeData对象下有对应的属性就赋值给state中对应的变量
// 加上vuex_前缀是防止变量名冲突也让人一目了然
vuex_user: gdz_lifeData.vuex_user ? gdz_lifeData.vuex_user : {},
vuex_token: gdz_lifeData.vuex_token ? gdz_lifeData.vuex_token : '',
// 如果vuex_version无需保存到本地永久存储无需gdz_lifeData.vuex_version方式
vuex_user: xcyjdt_lifeData.vuex_user ? xcyjdt_lifeData.vuex_user : {},
vuex_token: xcyjdt_lifeData.vuex_token ? xcyjdt_lifeData.vuex_token : '',
// 如果vuex_version无需保存到本地永久存储无需xcyjdt_lifeData.vuex_version方式
vuex_version: '1.0.0',
vuex_sign_base64: '',
@ -59,7 +59,7 @@ const store = new Vuex.Store({
saveKey = payload.name;
}
// 保存变量到本地,见顶部函数定义
savegdz_LifeData(saveKey, state[saveKey])
savexcyjdt_LifeData(saveKey, state[saveKey])
}
}
})

Loading…
Cancel
Save