bzkf30 vor 1 Jahr
Ursprung
Commit
cb9f64856e

+ 1 - 0
index.html

@@ -8,6 +8,7 @@
   </head>
   <body class="m-0 p-0">
     <div id="app" class="h-screen w-screen bg-hex-22252f flex flex-col text-white overflow-y-scroll"></div>
+    <script src="/config.js"></script>
     <script type="module" src="/src/main.ts"></script>
   </body>
 </html>

+ 41 - 0
public/config.js

@@ -0,0 +1,41 @@
+// 本地开发环境
+const local = {
+  web_pc: 'localhost',
+  origin: window.location.origin,
+  api: 'https://aimoocapi.bozedu.top',
+  oss: 'https://aimoocapi.bozedu.top',
+  uc: 'https://uc.dev.bozedu.net/',
+  openapi: 'https://openapi.dev.bozedu.net',
+}
+
+// 测试服环境
+const development = {
+  // web_pc: 'https://aimooc.bozedu.top',
+  origin: window.location.origin,
+  api: 'https://aimoocapi.bozedu.top',
+  oss: 'https://aimoocapi.bozedu.top',
+  uc: 'https://uc.dev.bozedu.net/',
+  openapi: 'https://openapi.dev.bozedu.net',
+}
+
+// // 正式服环境
+const production = {
+  // web_pc: 'https://aimooc.bozedu.net',
+  origin: window.location.origin,
+  api: 'https://aimoocapi.bozedu.net',
+  oss: 'https://aimoocapi.bozedu.net',
+  uc: 'https://uc.bozedu.net/',
+  openapi: 'https://openapi.bozedu.net',
+}
+
+function isWhich() {
+  if (window.location.href.startsWith(development.web_pc)) {
+    return development
+  } else if (window.location.href.startsWith(production.web_pc)) {
+    return production
+  } else {
+    return local
+  }
+}
+// window.GLOBAL_CONFIG = isWhich()
+window.GLOBAL_CONFIG = production

+ 7 - 4
src/pages/home/wode/index.vue

@@ -3,12 +3,14 @@
     <van-nav-bar title="个人中心"></van-nav-bar>
     <div class="relative my-30px">
       <div class="text-center">
-        <div class="w-100px h-100px bg-hex-cccccc rounded-50px m-auto"></div>
-        <div class="text-white mt-10px">名称</div>
+        <div class="w-100px h-100px m-auto">
+          <img class="w-full h-full rounded-50px" :src="user?.user_avatar" alt="" />
+        </div>
+        <div class="text-white mt-10px">{{user?.user_name}}</div>
       </div>
-      <div class="absolute right-20px top-0">
+      <!-- <div class="absolute right-20px top-0">
         <img class="w-22px" :src="editImg" alt="" />
-      </div>
+      </div> -->
     </div>
     <div class="px-20px">
       <div class="flex items-center p-4px box-border bg-hex-1A1B22 rounded-12px text-14px">
@@ -33,6 +35,7 @@
 import editImg from "~/assets/wode/edit.png";
 import syImg from "~/assets/wode/sy.png";
 import xxImg from "~/assets/wode/xx.png";
+import { user } from '~/store/user'
 
 const router = useRouter()
 

+ 40 - 5
src/pages/home/wode/wdsy.vue

@@ -7,14 +7,22 @@
     </van-nav-bar>
     <div class="px-20px">
       <div class="flex items-center p-4px box-border bg-hex-1A1B22 rounded-12px text-14px">
-        <div class="type_item" :class="activeType==index?'active':''" v-for="(item, index) in typeData" :key="index" @click="handleClick(index)">{{item}}</div>
+        <div class="type_item" :class="activeType==index?'active':''" v-for="(item, index) in typeData" :key="index" @click="handleTab(index)">{{item}}</div>
       </div>
-      <div class="mt-15px grid grid-cols-2 gap-12px">
+      <!-- <div class="mt-15px grid grid-cols-2 gap-12px">
         <div class="" v-for="i in 6" :key="i">
           <img class="w-full" :src="voiceImg" alt="" />
           <div class="text-center text-white mb-10px">声音{{i}}</div>
         </div>
-      </div>
+      </div> -->
+      <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多数据了" @load="onLoad">
+        <div class="grid grid-cols-2 gap-12px">
+          <div v-for="(item, index) in listData" :key="index" @click="handleClick(item)">
+            <img class="w-full" :src="voiceImg" alt="" />
+            <div class="text-center text-white mb-10px">{{ item.axa_name }}</div>
+          </div>
+        </div>
+      </van-list>
     </div>
   </div>
 </template>
@@ -31,10 +39,37 @@ function back() {
 const typeData = $ref(["通过", "不通过", "待审核"]);
 let activeType = $ref("");
 
-handleClick(0);
-function handleClick(index) {
+handleTab(0);
+function handleTab(index) {
   activeType = index;
 }
+
+
+let loading = $ref(false);
+let finished = $ref(false);
+let listData = $ref([]);
+let page = $ref("1");
+let limit = $ref("10");
+async function onLoad() {
+  let obj = {
+    page,
+    limit,
+    axa_status: ""
+  }
+  loading = true;
+  let {code, data} = await request({ url: '/aimooc/xnszr_audio/index', data: obj });
+  if(code == 1) {
+    listData = [...listData, ...data.page_data];
+    finished = data.total_page === page;
+    page++
+    loading = false;
+  }
+}
+
+
+function handleClick() {
+
+}
 </script>
 
 <style lang="scss" scoped>

+ 115 - 0
src/request/request.ts

@@ -0,0 +1,115 @@
+import type { AxiosRequestConfig } from 'axios'
+import axios from 'axios'
+import { showFailToast } from 'vant'
+import { user } from '~/store/user'
+import router from '../router/index'
+
+const token = user.value?.token
+export interface Response {
+  code: string
+  data: any
+  msg: string
+  status: any
+  statusText: any
+  headers: any
+  config: any
+}
+
+const instance = axios.create({
+  baseURL: (window as any).GLOBAL_CONFIG.api,
+  timeout: 60 * 1000,
+  headers: {
+    'Content-Type': 'application/x-www-form-urlencoded',
+  },
+  method: 'post',
+})
+
+instance.interceptors.request.use(
+  async (config) => {
+    // config.params = Object.assign({ token }, config.params)
+    if (config.method?.toLocaleLowerCase() === 'get' || config?.data?.file) {
+      config.params = Object.assign({ token }, config.params)
+    }
+    else {
+      config.data = Object.assign(
+        {
+          token: user.value?.token,
+          client: 'web',
+          api: 'json',
+          site: 'zjzs',
+          issubmit: (config.url?.endsWith('add') || config.url?.endsWith('edit')) ? '1' : undefined,
+        },
+        config.data)
+    }
+    return config
+  },
+  (error) => {
+    console.error('request error: ', error)
+    return Promise.reject(error)
+  },
+)
+
+// response interceptor
+instance.interceptors.response.use(
+  (response: { data: Response }) => {
+    if (response.config.url == "/openapi/wx/wx.php" && response.data.code == '401') {
+      return response.data
+    }
+    if (response.data.code === '10000') {
+      showFailToast('登录信息已过期,请重新登录')
+      return
+    }
+    if (response.data.code === undefined)
+      return response.data
+
+    response.data.code = response.data?.code?.toString()
+    response.data.msg = response.data.msg.replaceAll(/<.*?>/g, ' ')
+    const { code, msg } = response.data
+    if (code !== '1') {
+      showFailToast(msg)
+      return Promise.reject(response.data)
+    }
+    return response.data
+  },
+  (error) => {
+    console.error(`response error: ${error}`)
+    return Promise.reject(error)
+  },
+)
+
+export default (config: AxiosRequestConfig): Promise<Response> => instance.request(config)
+
+function obj2form(data: { [key: string]: any }) {
+  const formData = new FormData()
+  Object.keys(data).forEach(key => formData.append(key, data[key]))
+  return formData
+}
+
+export const REQUEST = {
+  empty: axios,
+  default: instance,
+  import: (c: Partial<AxiosRequestConfig>) => instance({
+    timeout: 10 * 60 * 1000,
+    transformRequest: [obj2form],
+    ...c,
+  }),
+  upload: (c: Partial<AxiosRequestConfig>) => instance({
+    timeout: 3 * 60 * 1000,
+    transformRequest: [obj2form],
+    ...c,
+  }),
+  download: (c: Partial<AxiosRequestConfig>) => instance({
+    timeout: 1 * 60 * 1000,
+    method: 'get',
+    params: { token, limit: 10000, page: 1, api: 'xls', ...c },
+  }),
+}
+
+export function download(url: string, data?: object | null) {
+  const params = Object.assign({ token, limit: 10000, page: 1, api: 'xls' }, data)
+  const paramsStr = Object.entries(params).map(([k, v]) => `${k}=${v}`).join('&')
+  const el = document.createElement('a')
+  const href = `${(window as any).GLOBAL_CONFIG.api}${url}?${paramsStr}`
+  el.setAttribute('href', href)
+  el.click()
+}

+ 11 - 1
src/router/index.ts

@@ -1,7 +1,7 @@
 import routes from 'virtual:generated-pages'
 import { createRouter, createWebHashHistory } from 'vue-router'
 
-// import { user } from '~/store/index'
+import { user } from '~/store/user'
 
 console.log('routes : ', routes)
 const router = createRouter({
@@ -20,3 +20,13 @@ router.beforeEach((to, from) => {
 })
 
 export default router
+
+
+
+const token = getUrlParams(window.location.href).token;
+if(token) {
+  const {code, data} = await request({ api: 'openapi', url: '/user/main/detail', data: { token }});
+  if(code == 1) {
+    user.value = data.one_info
+  }
+}

+ 82 - 0
src/store/user.d.ts

@@ -0,0 +1,82 @@
+export interface User {
+  about: string
+  address: string
+  area_id1: string
+  area_id2: string
+  area_id3: string
+  area_id4: string
+  create_dateline: string
+  email_token: string
+  email_token_exptime: string
+  email_validation: string
+  gender: string
+  ischeck: string
+  isdelete: string
+  modify_dateline: string
+  openid: string
+  parent_user_id: string
+  phone_validation: string
+  qq: string
+  setting: Setting
+  /**
+   * 用户token
+   */
+  token: string
+  user_abalance: string
+  user_address: { [key: string]: any }
+  user_alipay_account: string
+  /**
+   * 用户头像
+   */
+  user_avatar: string
+  user_birthday: string
+  user_cardno: string
+  user_dcash: string
+  user_detail_id: string
+  user_dqsj: string
+  /**
+   * email
+   */
+  user_email: string
+  user_group_id: string
+  user_id: string
+  user_level: string
+  user_level_id: string
+  /**
+   * 用户名
+   */
+  user_name: string
+  /**
+   * 用户昵称
+   */
+  user_nickname: string
+  user_password: string
+  user_phone: string
+  /**
+   * 用户真实姓名
+   */
+  user_realname: string
+  user_role_id: string
+  user_score: string
+  webchatopenid: string,
+  user_role_id_ext_now: string,
+}
+
+interface Setting {
+  site_address: string
+  site_email: string
+  site_hotphone: string
+  site_icp: string
+  site_linephone: string
+  site_wx_appid: string
+  site_wx_mchid: string
+  site_wx_sp_appid: string
+  site_wx_sp_mchid: string
+  site_wxapp_appid: string
+  sitedomain: string
+  sitefavicon: string
+  sitelogo: string
+  sitename: string
+  siteqrcode: string
+  user_failedlogin_max: string
+}

+ 14 - 0
src/store/user.ts

@@ -0,0 +1,14 @@
+import type { User } from './user.d'
+
+const sessionUser = localStorage.getItem('userInfo')
+export const user = ref<User | null>(sessionUser ? JSON.parse(sessionUser) : null)
+
+watch(
+  () => user.value,
+  (val) => {
+    if (val)
+      localStorage.setItem('userInfo', JSON.stringify(val))
+    else
+      localStorage.removeItem('userInfo')
+  },
+)

+ 19 - 0
src/utils/utils.js

@@ -0,0 +1,19 @@
+export function getUrlParams(url) {
+  // 通过 ? 分割获取后面的参数字符串
+  const urlStr = decodeURIComponent(url).split('?')[1]
+  if (urlStr != undefined) {
+    // 创建空对象存储参数
+    const obj = {}
+    // 再通过 & 将每一个参数单独分割出来
+    const paramsArr = urlStr.split('&')
+    for (let i = 0, len = paramsArr.length; i < len; i++) {
+      // 再通过 = 将每一个参数分割为 key:value 的形式
+      const arr = paramsArr[i].split('=')
+      obj[arr[0]] = arr[1]
+    }
+    return obj
+  }
+  else {
+    return {}
+  }
+}

+ 1 - 1
vite.config.ts

@@ -58,7 +58,7 @@ export default defineConfig({
       ],
       dts: true,
       dirs: [
-        './src/composables',
+        // './src/composables',
         './src/request',
         './src/utils',
       ],