Commit 454ae70b authored by Jenny's avatar Jenny

feat: 全局数据

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