feat(docs): 自动获取版本号

This commit is contained in:
sight 2022-03-31 03:37:01 +08:00
parent 6d5960cdb5
commit 5a87ed2285
4 changed files with 30 additions and 4 deletions

View File

@ -212,7 +212,7 @@
</a> </a>
</li> </li>
<li class="layui-nav-item"> <li class="layui-nav-item">
<a href="javascript:void(0)"> 0.4.4 </a> <a href="javascript:void(0)"> {{ layuiVueVersion }} </a>
</li> </li>
</ul> </ul>
</lay-header> </lay-header>
@ -221,12 +221,13 @@
</lay-config-provider> </lay-config-provider>
</template> </template>
<script> <script>
import { ref, watch } from "vue"; import { ref, watch, computed, provide } from "vue";
import { useRouter, useRoute } from "vue-router"; import { useRouter, useRoute } from "vue-router";
import menu from "../view/utils/menus"; import menu from "../view/utils/menus";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import zh_CN from "../locales/zh_CN.ts"; import zh_CN from "../locales/zh_CN.ts";
import en_US from "../locales/en_US.ts"; import en_US from "../locales/en_US.ts";
import { getLayuiVueVersion } from "../../../src/utils/getLayuiVueVersion.ts"
export default { export default {
setup() { setup() {
@ -266,6 +267,12 @@ export default {
}); });
}); });
const latestVer = getLayuiVueVersion();
const layuiVueVersion = computed(() =>
latestVer.value
?? import.meta.env.LAYUI_VUE_VERSION
)
watch(isDark, () => { watch(isDark, () => {
if (isDark.value) { if (isDark.value) {
theme.value = "dark"; theme.value = "dark";
@ -290,6 +297,7 @@ export default {
locale.value = lang; locale.value = lang;
}; };
provide('LayuiVueVersion', layuiVueVersion)
return { return {
t, t,
menus, menus,
@ -301,6 +309,7 @@ export default {
handleClick, handleClick,
changeLocale, changeLocale,
themeVariable, themeVariable,
layuiVueVersion,
}; };
}, },
}; };

View File

@ -20,7 +20,7 @@
> >
</div> </div>
<div class="site-version"> <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 <span
><router-link ><router-link
class="layui-inline site-down" class="layui-inline site-down"
@ -108,14 +108,17 @@
</template> </template>
<script> <script>
import { inject } from "vue";
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
export default { export default {
name: "index", name: "index",
setup() { setup() {
const { t } = useI18n(); const { t } = useI18n();
const layuiVueVersion = inject('LayuiVueVersion')
return { return {
t t,
layuiVueVersion
} }
} }
} }

View File

@ -1,6 +1,7 @@
import path from 'path' import path from 'path'
import { defineConfig } from 'vite' import { defineConfig } from 'vite'
import plugins from './src/plugin/common-plugins' import plugins from './src/plugin/common-plugins'
import pkg from '../package.json'
export default defineConfig({ export default defineConfig({
resolve: { resolve: {
@ -8,5 +9,8 @@ export default defineConfig({
'/@src': path.resolve(__dirname, './src'), '/@src': path.resolve(__dirname, './src'),
}, },
}, },
define: {
'import.meta.env.LAYUI_VUE_VERSION': JSON.stringify(pkg.version),
},
plugins, plugins,
}) })

View 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;
}