diff --git a/doc/@types/index.d.ts b/doc/@types/index.d.ts index 2c34f29..2783a69 100644 --- a/doc/@types/index.d.ts +++ b/doc/@types/index.d.ts @@ -19,6 +19,13 @@ declare namespace Doc { * vuex state */ interface state { + /** + * 当前服务器版本 + * * 来自服务器端 + * * 这是一个例子 + */ + version: string + /** * 是否 使用 移动设备 访问 * * 来自服务器端 diff --git a/doc/src/store/actions.ts b/doc/src/store/actions.ts index fc0f6cd..9575a20 100644 --- a/doc/src/store/actions.ts +++ b/doc/src/store/actions.ts @@ -1,6 +1,16 @@ import { globalHelper } from 'src/store/helpers' import { Tstore } from '@types' +import axios from 'axios' +import { isServer, injectGlobal } from 'src/envs' +import { commit, getState } from 'src/store' + +function get(url: string) { + if (isServer) url = `${injectGlobal.__INJECT_CONTEXT__.SERVER_HOST}${url}` + console.log('axios 发起请求:', url) + return axios.get(url) +} + export const actions = globalHelper.makeActions({ GET_SERVER_DATA(ctx, { id }: { id: number }) { let resove @@ -11,6 +21,19 @@ export const actions = globalHelper.makeActions({ }) }, 1000) return promise + }, + GET_SERVER_VERSION(ctx) { + const version = getState(ctx, 'version') + if (version) { + console.log('version 已经被请求过了') + return + } + + return get('/private/version').then(({ data }) => { + const version = data.version.join('.') + console.log('axios 获取当前版本号:', version) + commit(ctx, 'SET_VERSION', { version }) + }) } }) diff --git a/doc/src/store/mutations.ts b/doc/src/store/mutations.ts index a2556e6..7378776 100644 --- a/doc/src/store/mutations.ts +++ b/doc/src/store/mutations.ts @@ -12,6 +12,9 @@ export const mutations = globalHelper.makeMutations({ SET_testHotLoadingVuex: (state, { number }: { number: number }) => { state.testHotLoadingVuex += number * 1 }, + SET_VERSION: (state, { version }: Pick) => { + state.version = version + }, }) export default mutations diff --git a/doc/src/store/state.ts b/doc/src/store/state.ts index d5f656e..c57cf15 100644 --- a/doc/src/store/state.ts +++ b/doc/src/store/state.ts @@ -3,6 +3,7 @@ import { Tstore } from '@types' export default function state(): Tstore.state { return { isMobile: false, + version: '', hello: '', testHotLoadingVuex: 0, initialReplaceStateUrl: '', diff --git a/doc/src/views/index.vue b/doc/src/views/index.vue index 6c04934..c9058fa 100644 --- a/doc/src/views/index.vue +++ b/doc/src/views/index.vue @@ -1,5 +1,6 @@