feat(docs): 自动获取版本号
This commit is contained in:
parent
6d5960cdb5
commit
5a87ed2285
@ -212,7 +212,7 @@
|
||||
</a>
|
||||
</li>
|
||||
<li class="layui-nav-item">
|
||||
<a href="javascript:void(0)"> 0.4.4 </a>
|
||||
<a href="javascript:void(0)"> {{ layuiVueVersion }} </a>
|
||||
</li>
|
||||
</ul>
|
||||
</lay-header>
|
||||
@ -221,12 +221,13 @@
|
||||
</lay-config-provider>
|
||||
</template>
|
||||
<script>
|
||||
import { ref, watch } from "vue";
|
||||
import { ref, watch, computed, provide } from "vue";
|
||||
import { useRouter, useRoute } from "vue-router";
|
||||
import menu from "../view/utils/menus";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import zh_CN from "../locales/zh_CN.ts";
|
||||
import en_US from "../locales/en_US.ts";
|
||||
import { getLayuiVueVersion } from "../../../src/utils/getLayuiVueVersion.ts"
|
||||
|
||||
export default {
|
||||
setup() {
|
||||
@ -266,6 +267,12 @@ export default {
|
||||
});
|
||||
});
|
||||
|
||||
const latestVer = getLayuiVueVersion();
|
||||
const layuiVueVersion = computed(() =>
|
||||
latestVer.value
|
||||
?? import.meta.env.LAYUI_VUE_VERSION
|
||||
)
|
||||
|
||||
watch(isDark, () => {
|
||||
if (isDark.value) {
|
||||
theme.value = "dark";
|
||||
@ -290,6 +297,7 @@ export default {
|
||||
locale.value = lang;
|
||||
};
|
||||
|
||||
provide('LayuiVueVersion', layuiVueVersion)
|
||||
return {
|
||||
t,
|
||||
menus,
|
||||
@ -301,6 +309,7 @@ export default {
|
||||
handleClick,
|
||||
changeLocale,
|
||||
themeVariable,
|
||||
layuiVueVersion,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
@ -20,7 +20,7 @@
|
||||
>
|
||||
</div>
|
||||
<div class="site-version">
|
||||
<span>{{ t('home.version') }}:v<cite class="site-showv">0.4.4</cite></span>
|
||||
<span>{{ t('home.version') }}:v<cite class="site-showv">{{ layuiVueVersion }}</cite></span>
|
||||
<span
|
||||
><router-link
|
||||
class="layui-inline site-down"
|
||||
@ -108,14 +108,17 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { inject } from "vue";
|
||||
import { useI18n } from 'vue-i18n';
|
||||
export default {
|
||||
name: "index",
|
||||
setup() {
|
||||
const { t } = useI18n();
|
||||
const layuiVueVersion = inject('LayuiVueVersion')
|
||||
|
||||
return {
|
||||
t
|
||||
t,
|
||||
layuiVueVersion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import path from 'path'
|
||||
import { defineConfig } from 'vite'
|
||||
import plugins from './src/plugin/common-plugins'
|
||||
import pkg from '../package.json'
|
||||
|
||||
export default defineConfig({
|
||||
resolve: {
|
||||
@ -8,5 +9,8 @@ export default defineConfig({
|
||||
'/@src': path.resolve(__dirname, './src'),
|
||||
},
|
||||
},
|
||||
define: {
|
||||
'import.meta.env.LAYUI_VUE_VERSION': JSON.stringify(pkg.version),
|
||||
},
|
||||
plugins,
|
||||
})
|
10
src/utils/getLayuiVueVersion.ts
Normal file
10
src/utils/getLayuiVueVersion.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { useFetch } from "@vueuse/core";
|
||||
|
||||
export function getLayuiVueVersion() {
|
||||
const { data } = useFetch(`https://data.jsdelivr.com/v1/package/npm/@layui/layui-vue`, {
|
||||
timeout: 1000 * 2,
|
||||
initialData: '',
|
||||
afterFetch: (ctx) => ((ctx.data = ctx.data.tags.latest), ctx)
|
||||
}).json()
|
||||
return data;
|
||||
}
|
Loading…
Reference in New Issue
Block a user