|
@@ -0,0 +1,78 @@
|
|
|
+const KEEPSTORAGE = 'KEEPSTORAGE'
|
|
|
+const SETUPFUNCS = 'SETUPFUNCS'
|
|
|
+
|
|
|
+export default {
|
|
|
+ namespaced: true,
|
|
|
+ state: {
|
|
|
+ funcs: [ // 預計以後會開放的功能 以下以最大數量為主)
|
|
|
+ { func: 'WORKS', para: 1, get: null, exp: null, active: false }, // 作品收集任務數
|
|
|
+ { func: 'CLIENTS', para: 10, get: null, exp: null, active: false }, // 連線人數 (掃碼改為50)
|
|
|
+ { func: 'PAGEQTY', para: 50, get: null, exp: null, active: false } // 頁面數
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ getters: {
|
|
|
+ // 取得指定的功能設定
|
|
|
+ getFunc: (state) => (func) => {
|
|
|
+ return state.funcs.find(item => item.func === func)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mutations: {
|
|
|
+ [KEEPSTORAGE](state, data) {
|
|
|
+ let keys = Object.keys(data)
|
|
|
+ keys.forEach(key => {
|
|
|
+ state[key] = data[key]
|
|
|
+ })
|
|
|
+ },
|
|
|
+ [SETUPFUNCS](state, data) {
|
|
|
+ state.funcs = data
|
|
|
+ }
|
|
|
+ },
|
|
|
+ actions: {
|
|
|
+ /**
|
|
|
+ * 設定開放的功能
|
|
|
+ * @param {Object} data
|
|
|
+ */
|
|
|
+ setupFuncs(context, data) {
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ var nowTime = new Date()
|
|
|
+ let nT = parseInt(Date.parse(nowTime)/1000) // 用十碼計算
|
|
|
+ data.forEach( item => {
|
|
|
+ let active = false
|
|
|
+ let exp = item.exp
|
|
|
+
|
|
|
+ // 如果超過10碼調整為10碼
|
|
|
+ if(!!item.exp && item.exp.toString().length > 10 ) {
|
|
|
+ exp = parseInt(exp/1000)
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!!item.exp && (exp - nT) > 0) {
|
|
|
+ active = true
|
|
|
+ }
|
|
|
+
|
|
|
+ item.active = active
|
|
|
+ })
|
|
|
+ context.commit(SETUPFUNCS, data)
|
|
|
+ context.dispatch('saveState') // 存到sessionStorage
|
|
|
+ resolve(true)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * NOTE: 維持 vuex state 的資訊
|
|
|
+ */
|
|
|
+ keepState(context) {
|
|
|
+ if(!jsFn.IsEmpty(sessionStorage.getItem('funcsData'))) {
|
|
|
+ let data = JSON.parse(decodeURIComponent(sessionStorage.getItem('funcsData'),'utf-8'))
|
|
|
+ context.commit(KEEPSTORAGE, data)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * NOTE: 儲存現在 state 的資訊
|
|
|
+ */
|
|
|
+ saveState(context) {
|
|
|
+ let saveData = {
|
|
|
+ funcs: context.state.funcs
|
|
|
+ }
|
|
|
+ sessionStorage.setItem('funcsData', encodeURIComponent(JSON.stringify(saveData), 'utf-8'))
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|