guhongwei 2 tahun lalu
induk
melakukan
447586f264

+ 4 - 0
env.d.ts

@@ -1 +1,5 @@
 /// <reference types="vite/client" />
+interface ImportMetaEnv {
+  VITE_BASE_URL: string
+  VITE_OUT_DIR: string
+}

+ 55 - 0
src/components/ValidCode.vue

@@ -0,0 +1,55 @@
+<template>
+  <div id="validcode">
+    <div class="code" @click="resetCode()">
+      <span v-for="i in list" :key="i.code" :style="getStyle(i)">{{ i.code }}</span>
+    </div>
+  </div>
+</template>
+<script setup lang="ts">
+import type { Ref } from 'vue'
+import { ref, onMounted } from 'vue'
+const emit = defineEmits(['toCode'])
+const list: Ref<any> = ref([])
+onMounted(() => {
+  // 创建验证码
+  createCode()
+})
+// 创建验证码
+const createCode = () => {
+  const len = 4
+  const codeList = []
+  const chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz0123456789'
+  const charsLen = chars.length
+  for (let i = 0; i < len; i++) {
+    const rgb = [Math.round(Math.random() * 220), Math.round(Math.random() * 240), Math.round(Math.random() * 200)]
+    codeList.push({
+      code: chars.charAt(Math.floor(Math.random() * charsLen)),
+      color: `rgb(${rgb})`,
+      fontSize: `1${[Math.floor(Math.random() * 10)]}px`,
+      padding: `${[Math.floor(Math.random() * 10)]}px`,
+      transform: `rotate(${Math.floor(Math.random() * 90) - Math.floor(Math.random() * 90)}deg)`
+    })
+  }
+  list.value = codeList
+  const codeInfo = codeList.map((item) => item.code).join('')
+  emit('toCode', codeInfo)
+}
+// 验证码样式
+const getStyle = (e: any) => {
+  return `color: ${e.color}; font-size: ${e.fontSize}; padding: ${e.padding}; transform: ${e.transform}`
+}
+// 重构验证码
+const resetCode = () => {
+  createCode()
+}
+</script>
+<style scoped lang="scss">
+.code {
+  width: 100px;
+  height: 40px;
+  line-height: 40px;
+  text-align: center;
+  border-radius: 5px;
+  border: 1px solid #dcdfe6;
+}
+</style>

+ 2 - 2
src/components/web-frame/home.vue

@@ -18,8 +18,8 @@
 // 组件
 import cHeader from './parts/header.vue'
 import cFoot from './parts/foot.vue'
-import type { Ref } from 'vue'
-import { ref, toRefs, onMounted } from 'vue'
+// import type { Ref } from 'vue'
+import { ref, onMounted } from 'vue'
 const loading = ref(false)
 onMounted(async () => {
   loading.value = true

+ 21 - 25
src/components/web-frame/parts/header.vue

@@ -7,11 +7,10 @@
             <el-col class="one_title">
               <el-col :span="12" class="one-1"> 欢迎来到{{ siteInfos.zhTitle }} </el-col>
               <el-col :span="12" class="one-2">
-                <el-button type="primary" size="small" @click="toLogin('adminLogin')" v-if="user == null">管理登录</el-button>
-                <el-button type="primary" size="small" @click="toLogin('userLogin')" v-if="user == null">平台登录</el-button>
-                <el-button type="danger" size="small" @click="toLogout()" v-if="user && user._id != null">退出登录</el-button>
-                <el-button type="primary" size="small" @click="toCenter()" v-if="user && user._id != null">个人中心</el-button>
-                <span class="textOver">{{ user && user._id ? user.name || user.title : '游客' }}</span>
+                <el-button size="small">{{ user & user._id ? user.name : '游客' }}</el-button>
+                <el-button type="primary" size="small" @click="toLogin" v-if="user && !user._id">平台登录</el-button>
+                <el-button type="primary" size="small" @click="toCenter" v-if="user && user._id">个人中心</el-button>
+                <el-button type="danger" size="small" @click="toLogout" v-if="user && user._id">退出登录</el-button>
               </el-col>
             </el-col>
           </div>
@@ -108,24 +107,31 @@ const search = async () => {
   }
 }
 // 跳转登录
-const toLogin = (type) => {
-  router.push({ path: `/login/${type}` })
-}
-// 首页
-const toHome = () => {
-  router.push({ path: '/' })
+const toLogin = () => {
+  router.push({ path: `/login` })
 }
 // 个人中心
 const toCenter = () => {
-  console.log('1')
-  // let token = sessionStorage.getItem('token');
-  // if (token) window.location.href = `http://localhost:8002/liveuser/login?token=${token}`;
+  let env = import.meta.env.VITE_APP_ENV
+  let path = ''
+  if (env == 'development') {
+    if (user.value.type == '0' || user.value.type == '1' || user.value.type == '2' || user.value.type == '3') path = 'http://localhost:8003/zkzxadmin'
+    else if (user.value.type == '4' || user.value.type == '5' || user.value.type == '6') path = 'http://localhost:8002/zkzxuser'
+  } else {
+    if (user.value.type == '0' || user.value.type == '1' || user.value.type == '2' || user.value.type == '3') path = '/zkzxadmin'
+    else if (user.value.type == '4' || user.value.type == '5' || user.value.type == '6') path = '/zkzxuser'
+  }
+  window.open(path)
 }
 // 退出登录
 const toLogout = () => {
-  sessionStorage.removeItem('token')
+  localStorage.removeItem('token')
   location.reload()
 }
+// 首页
+const toHome = () => {
+  router.push({ path: '/' })
+}
 </script>
 <style scoped lang="scss">
 .main {
@@ -145,16 +151,6 @@ const toLogout = () => {
       flex-wrap: wrap;
       .one-2 {
         text-align: right;
-        span {
-          color: #000;
-          padding: 0 10px 0 0;
-          float: right;
-          width: 68%;
-        }
-        .el-button {
-          float: right;
-          margin: 5px;
-        }
       }
     }
   }

+ 27 - 0
src/stores/user/token.ts

@@ -0,0 +1,27 @@
+import { ref, computed } from 'vue'
+import { defineStore } from 'pinia'
+import { AxiosWrapper } from '@/util/axios-wrapper'
+
+import type { IQueryResult } from '@/util/types.util'
+const axios = new AxiosWrapper()
+const api = {
+  url: `/zkzx/v2/api/token`
+}
+export const TokenStore = defineStore('token', () => {
+  const count = ref(0)
+  const doubleCount = computed(() => count.value * 2)
+  function increment() {
+    count.value++
+  }
+
+  const tokenInfo = async (): Promise<IQueryResult> => {
+    const res = await axios.$get(`${api.url}/tokenView`)
+    return res
+  }
+  return {
+    count,
+    doubleCount,
+    increment,
+    tokenInfo
+  }
+})

+ 5 - 5
vite.config.ts

@@ -1,15 +1,15 @@
 import { fileURLToPath, URL } from 'node:url'
 import { defineConfig } from 'vite'
 import vue from '@vitejs/plugin-vue'
-const path = require('path')
-const common = path.resolve(__dirname, '../common')
-export default defineConfig(({ mode }) => {
+export default defineConfig(() => {
   return {
     plugins: [vue()],
+    server: {
+      fs: { strict: false }
+    },
     resolve: {
       alias: {
-        '@': fileURLToPath(new URL('./src', import.meta.url)),
-        '@common': common
+        '@': fileURLToPath(new URL('./src', import.meta.url))
       }
     }
   }