Просмотр исходного кода

Merge branch 'dev-lhf' into 'dev'

Dev lhf

See merge request product-group-fe/sfy-safety-group/sfy-safety!50
楼航飞 11 месяцев назад
Родитель
Сommit
f0ec929701
5 измененных файлов с 32 добавлено и 18 удалено
  1. 16 7
      build/vite/plugin/html.ts
  2. 8 5
      index.html
  3. 3 3
      src/components/Login.vue
  4. 3 2
      src/components/UserInfo.vue
  5. 2 1
      tsconfig.node.json

+ 16 - 7
build/vite/plugin/html.ts

@@ -7,26 +7,28 @@ import { createHtmlPlugin } from 'vite-plugin-html';
 // import pkg from '../../../package.json';
 // import { GLOB_CONFIG_FILE_NAME } from '../../constant';
 import { simpleGit } from 'simple-git';
+import dayjs from 'dayjs';
 const git = simpleGit();
 
 async function getLatestHash() {
   const gitLog = await git.log();
+
   /** 截取git hash值最后8位 */
   const lastStrNum = 8;
   return gitLog.latest?.hash.substring(-lastStrNum, lastStrNum);
 }
 
+async function getBuildInfo() {
+  const { current } = await git.branchLocal();
+  const hash = await getLatestHash();
+  return { currentBranch: current, hash };
+}
+
 export function configHtmlPlugin(env: ViteEnv, isBuild: boolean): Promise<PluginOption[]> {
   const { VITE_GLOB_APP_TITLE } = env;
 
-  const path = './';
-
-  // const getAppConfigSrc = () => {
-  //   return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`;
-  // };
-
   return new Promise((resolve) => {
-    getLatestHash().then((hash) => {
+    getBuildInfo().then(({ currentBranch, hash }) => {
       const htmlPlugin: PluginOption[] = createHtmlPlugin({
         minify: isBuild,
         inject: {
@@ -34,7 +36,14 @@ export function configHtmlPlugin(env: ViteEnv, isBuild: boolean): Promise<Plugin
           data: {
             title: VITE_GLOB_APP_TITLE,
             hash,
+            injectScript: `
+            <script type="text/javascript">
+  console.log("%cbuild branch, ${currentBranch}","background:#1777FF; padding: 3px 6px; border-radius: 4px" )
+  console.log("%cbuild version: ${hash}", "background:#1777FF; padding: 3px 6px; border-radius: 4px");
+  console.log("build time, ${dayjs().format('YYYY-MM-DD HH:mm:ss')}", )
+  </script>`,
           },
+
           // // Embed the generated app.config.js file
           // tags: isBuild
           //   ? [

+ 8 - 5
index.html

@@ -120,7 +120,7 @@
     </div>
   </div>
   <div class="versionHash">
-    <span>version hash: <%= hash %></span>
+    <span>version hash: <%- hash %></span>
     <style>
       .versionHash {
         position: fixed;
@@ -129,13 +129,16 @@
         font-size: 12px;
         color: #ccc;
         z-index: 10000;
+        display: none;
       }
     </style>
   </div>
-  <script>
-    var globalThis = window;
-  </script>
-  <script src="/src/main.ts" type="module"></script>
+  <%- injectScript %>
+
+    <script>
+      var globalThis = window;
+    </script>
+    <script src="/src/main.ts" type="module"></script>
 </body>
 
 </html>

+ 3 - 3
src/components/Login.vue

@@ -61,19 +61,19 @@
   const userStore = useUserStore();
 
   const formValue = reactive({
-    username: '',
+    username: userStore.info.username,
     password: '',
   });
   const emit = defineEmits(['close']);
   const formRef = ref<FormInstance>();
   const handleLogin = () => {
     if (!formRef.value) return;
-    formRef.value.validate((valid: boolean, ...rest) => {
+    formRef.value.validate((valid: boolean) => {
       if (valid) {
         console.log('valid', formValue);
         userStore
           .login(formValue)
-          .then((res) => {
+          .then(() => {
             window.location.reload();
           })
           .catch((err) => {

+ 3 - 2
src/components/UserInfo.vue

@@ -23,9 +23,10 @@
   const userStore = useUserStore();
   const emit = defineEmits(['switchAccount', 'modifyPassword']);
 
-  const handleLogout = () => {
+  const handleLogout = async () => {
     userStore.logout();
-    router.push({ path: '/home' });
+    await router.push({ path: '/home' });
+    window.location.reload();
   };
 </script>
 

+ 2 - 1
tsconfig.node.json

@@ -9,7 +9,7 @@
     "module": "ESNext",
     "skipLibCheck": true,
     /* Bundler mode */
-    "moduleResolution": "bundler",
+    "moduleResolution": "node",
     "isolatedModules": true,
     "moduleDetection": "force",
     "emitDeclarationOnly": true,
@@ -18,6 +18,7 @@
     "noUnusedLocals": true,
     "noUnusedParameters": true,
     "noFallthroughCasesInSwitch": true,
+    "allowSyntheticDefaultImports": true,
   },
   "include": [
     "vite.config.ts",