Skip to content

Commit

Permalink
feat:
Browse files Browse the repository at this point in the history
1.删除多余文件
2.新增前端发布时显示版本及编译时间
3.支持 vue3 ref sugar
  • Loading branch information
orziz committed Jun 8, 2022
1 parent 3939e27 commit da9602a
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 20 deletions.
4 changes: 4 additions & 0 deletions web/build/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "",
"buildTime": ""
}
46 changes: 46 additions & 0 deletions web/build/plugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { Plugin } from "vite"
import { resolve } from "path"
import { readFileSync, writeFileSync } from "fs"

function getFormatTime() {
let date = new Date();
let year: string | number = date.getFullYear();
let month: string | number = date.getMonth() + 1;
let day: string | number = date.getDate();
let h: string | number = date.getHours();
let m: string | number = date.getMinutes();
let s: string | number = date.getSeconds();
if (month < 10) month = "0"+month;
if (day < 10) day = "0"+day;
if (h < 10) h = "0"+h;
if (m < 10) m = "0"+m;
if (s < 10) s = "0"+s;
return [year, month, day].join("-") + " " + [h, m, s].join(":");
}

/**
* 自动修改版本号
* @returns
*/
export function changePackageVersion(): Plugin {
if (process.env.NODE_ENV === "production") {
let packagePath = resolve(__dirname, "./info.json");
let packageStr = readFileSync(packagePath, {
encoding: "utf-8"
});
let packageJson = JSON.parse(packageStr);
let version = packageJson.version;
let versionArr: (string | number)[] = version.split(".");
let lastVersionNum = +versionArr[versionArr.length - 1];
lastVersionNum++;
versionArr.splice(versionArr.length - 1, 1, lastVersionNum);
packageJson.version = versionArr.join(".");
packageJson.buildTime = getFormatTime();
writeFileSync(packagePath, JSON.stringify(packageJson, null, "\t"), {
encoding: "utf-8"
})
}
return {
name: "changePackageVersion"
}
}
11 changes: 0 additions & 11 deletions web/jsconfig.json

This file was deleted.

2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@tauri-apps/cli": "^1.0.0-rc.7",
"@types/node": "^17.0.35",
"@types/qrcode": "^1.4.2",
"@vitejs/plugin-vue": "^2.3.1",
"@vitejs/plugin-vue": "^2.3.3",
"@vue/compiler-sfc": "^3.2.36",
"typescript": "^4.7.2",
"vite": "^2.9.2"
Expand Down
8 changes: 8 additions & 0 deletions web/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@
import { computed } from 'vue';
import { useStore } from 'vuex';
import { darkTheme } from 'naive-ui';
import { version, buildTime } from "../build/info.json";

const store = useStore();
const theme = computed(() => (store.state.theme === 'dark' ? darkTheme : null));

console.log(`%c Release Build Info
%cVersion v${version}
BuildTime ${buildTime}`
, "background:#000;color:#FFF;font-weight:bold;"
, "background:#FFF;color:#000;"
)
</script>

<style lang="less">
Expand Down
2 changes: 1 addition & 1 deletion web/src/types/NetParams.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ declare module NetParams {
}

interface PostGetTags {
type: 'hot' | string,
type: 'hot' | 'new',
num: number
}

Expand Down
4 changes: 2 additions & 2 deletions web/src/views/Topic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { ref, onMounted } from 'vue';
import { getTags } from '@/api/post';

const tags = ref<Item.TagProps[]>([]);
const tagType = ref('hot');
const tagType = ref<"hot" | "new">('hot');
const loading = ref(false);

const loadTags = () => {
Expand All @@ -61,7 +61,7 @@ const loadTags = () => {
loading.value = false;
});
};
const changeTab = (tab: string) => {
const changeTab = (tab: "hot" | "new") => {
tagType.value = tab;
loadTags();
};
Expand Down
6 changes: 5 additions & 1 deletion web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'

import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import { changePackageVersion } from './build/plugins';
// https://vitejs.dev/config/
export default defineConfig({
server: {
host: '0.0.0.0'
},
plugins: [
vue(),
changePackageVersion(),
vue({
reactivityTransform: [/src/]
}),
Components({
resolvers: [NaiveUiResolver()]
})
Expand Down
8 changes: 4 additions & 4 deletions web/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@
resolved "https://registry.npmmirror.com/@vicons/tabler/-/tabler-0.12.0.tgz"
integrity sha512-3+wUFuxb7e8OzZ8Wryct1pzfA2vyoF4lwW98O9s27ZrfCGaJGNmqG+q8A7vQ92Mf+COCgxpK+rhNPTtTvaU6qw==

"@vitejs/plugin-vue@^2.3.1":
version "2.3.1"
resolved "https://registry.npmmirror.com/@vitejs/plugin-vue/-/plugin-vue-2.3.1.tgz"
integrity sha512-YNzBt8+jt6bSwpt7LP890U1UcTOIZZxfpE5WOJ638PNxSEKOqAi0+FSKS0nVeukfdZ0Ai/H7AFd6k3hayfGZqQ==
"@vitejs/plugin-vue@^2.3.3":
version "2.3.3"
resolved "https://registry.npmmirror.com/@vitejs/plugin-vue/-/plugin-vue-2.3.3.tgz#fbf80cc039b82ac21a1acb0f0478de8f61fbf600"
integrity sha512-SmQLDyhz+6lGJhPELsBdzXGc+AcaT8stgkbiTFGpXPe8Tl1tJaBw1A6pxDqDuRsVkD8uscrkx3hA7QDOoKYtyw==

"@vue/[email protected]":
version "3.2.33"
Expand Down

0 comments on commit da9602a

Please sign in to comment.