Commit 454ae70b authored by Jenny's avatar Jenny

feat: 全局数据

parent 4cfcbebd
......@@ -38,7 +38,13 @@ export default {
* 全局数据
*/
handlePublicData (value) {
if (!this.globalData) return
const { dataProcessing } = { ...value }
if (dataProcessing) {
elementData.value.dataList = this.$u.common.converFunction(dataProcessing, JSON.parse(this.globalData))
return false
}
elementData.value.dataList = JSON.parse(this.globalData)
},
/**
* 配置数据 - 数据集
......@@ -101,6 +107,13 @@ export default {
},
immediate: true,
deep: true
},
/**
* 全局数据更新监测
*/
globalData () {
console.log('----globalData----', this.globalData)
if (this.elementInfo.data.dataType === 'public') this.handlePublicData(this.elementInfo.data)
}
}
}
......@@ -37,7 +37,8 @@
data() {
return {
reportInfo: {},
reportData: []
reportData: [],
timer: null
}
},
computed: {
......@@ -54,52 +55,68 @@
async onLoad() {
this.getReportList()
},
onShow() {
this.userAuthCheck()
},
onShow() {
this.userAuthCheck()
},
methods: {
//检查是否登录
userAuthCheck() {
var userId = uni.getStorageSync('userId')
this.getNewestAuthFromServer()
var authorized = uni.getStorageSync('authorized')
if (userId) {
if (authorized) {
} else {
uni.reLaunch({
url:'../login/authorized'
})
}
} else {
uni.reLaunch({
url: '../login/login'
})
}
},
//获取最新的授权信息
getNewestAuthFromServer() {
var param = {
id: uni.getStorageSync('userId')
}
this.$u.api.getAuthorized(param).then(res=>{
const { Status, Result } = res.data
if (Status === 'true') {
uni.setStorageSync('authorized', Result.authorized)
}
})
},
//检查是否登录
userAuthCheck() {
var userId = uni.getStorageSync('userId')
this.getNewestAuthFromServer()
var authorized = uni.getStorageSync('authorized')
if (userId) {
if (authorized) {
} else {
uni.reLaunch({
url:'../login/authorized'
})
}
} else {
uni.reLaunch({
url: '../login/login'
})
}
},
//获取最新的授权信息
getNewestAuthFromServer() {
var param = {
id: uni.getStorageSync('userId')
}
this.$u.api.getAuthorized(param).then(res=>{
const { Status, Result } = res.data
if (Status === 'true') {
uni.setStorageSync('authorized', Result.authorized)
}
})
},
/**
* 获取页面报表配置
*/
async getReportList() {
clearInterval(this.timer)
let res = await this.$u.api.getReportList({id: '61c424a4c06bff0ce05d9a53'})
const { Status, Result } = res.data
const { Status, Result: { info, list } } = res.data
if (Status === 'true') {
this.reportInfo = Result.info
this.reportData = Result.list
this.reportInfo = info
this.reportData = list
if(info.dataUrl) {
this.getGlobalData(info)
if(info.dataPollingInterval) {
this.timer = setInterval(() => {
this.getGlobalData(info)
}, parseInt(info.dataPollingInterval) * 1000)
}
}
}
},
/**
* 获取全局接口数据
*/
async getGlobalData(info) {
const dataUrl = info.dataUrl.replace(/^(\/dashboardCharts)?|^(\/dashboardAPI)?/, '')
let res = await this.$u[info.dataMethod.toLowerCase()](dataUrl, info.dataFormatter)
this.$u.vuex('globalData', JSON.stringify(res.data))
}
},
onReachBottom() {
......
......@@ -12,7 +12,7 @@ try {
}
// 需要永久存储,且在下次 APP 启动需要取出的,在 state 中的变量名。
let saveStateKeys = ['vuex_user', 'vuex_token']
let saveStateKeys = ['vuex_token']
// 保存变量到本地存储中
const saveLifeData = function(key, value) {
......@@ -30,8 +30,8 @@ const saveLifeData = function(key, value) {
const store = new Vuex.Store({
state: {
vuex_user: lifeData.vuex_user || { name: 'test' },
vuex_token: lifeData.vuex_token || '',
globalData: ""
},
mutations: {
$uStore(state, payload) {
......
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