Jelajahi Sumber

feat: 完成功能

rindy 9 bulan lalu
induk
melakukan
dd5695fee0
7 mengubah file dengan 77 tambahan dan 10 penghapusan
  1. 1 1
      index.html
  2. 6 2
      src/App.vue
  3. 53 4
      src/api/alova.ts
  4. 7 0
      src/api/module/editor.ts
  5. 2 1
      src/api/url.ts
  6. 7 1
      src/store/main.ts
  7. 1 1
      vite.config.ts

+ 1 - 1
index.html

@@ -4,7 +4,7 @@
     <meta charset="UTF-8" />
     <link rel="icon" href="/favicon.ico" />
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-    <title>Vite App</title>
+    <title>场景功能设置</title>
   </head>
   <body>
     <div id="app"></div>

+ 6 - 2
src/App.vue

@@ -271,8 +271,12 @@ const handleUpdateValue = (value: string) => {
 onMounted(() => {
   const sceneCode = params.m ? String(params.m) : 'KJ-t-3Y6dxgyehDk'
   main.setSceneCode(sceneCode)
-  main.getSceneInfo()
-  setSceneLink(`${import.meta.env.VITE_KANKAN_PREFIX}/spg.html?m=${main.sceneCode}`)
+  main.getSceneInfo().then((data)=>{
+    if(data)  {
+      setSceneLink(`${import.meta.env.VITE_KANKAN_PREFIX}/spg.html?m=${main.sceneCode}`)
+    }
+  })
+  
   setSceneRef(sceneRef.value)
 })
 

+ 53 - 4
src/api/alova.ts

@@ -4,6 +4,45 @@ import adapterFetch from 'alova/fetch'
 import { createDiscreteApi } from 'naive-ui'
 
 const { message } = createDiscreteApi(['message'])
+const { dialog }  = createDiscreteApi(['dialog'])
+const statusCode = {
+  "5005": "场景不存在",
+  "5012": "数据不正常",
+  "5014": "您没有该场景的编辑权限。",
+  "5018": "zip 文件只能有一层目录或无目录",
+  "5019": "必须有且仅有一个 obj 和 mtl 文件",
+  "5020": "贴图需控制在 1.5MB 以内,obj 文件需要控制在 20MB 以内。",
+  "5021": "场景密钥不正确",
+  "5025": "数据包不存在,请先打成 zip 包",
+  "5033": "计算中",
+  "5034": "场景已封存",
+  "5039": "系统繁忙,请稍后再试。",
+  "5043": "打包 zip 失败",
+  "5059": "该压缩包无可用 obj 或 mtl 文件",
+  "5060": "obj 文件名应为 mesh.obj",
+  "5062": "无可用 jpg文件",
+  "5065": "上传失败。zip 压缩包内所有文件如贴图、obj、mtl 等需放在根目录同一个文件夹中。",
+  "5066": "后台正在处理您的请求,耐心等待。",
+  "5068": "json 文件丢失,请在原始文件中找到该文件并重新打包上传。",
+  "5069": "json 文件错误,请在原始文件中找到该文件并重新打包上传。",
+  "5070": "请上传正确的楼层文件,文件数量需与原始文件一致。",
+  "7004": "热点数据不能为空",
+  "7005": "查询不到热点数据",
+  "7006": "目录不存在",
+  "7007": "文件格式不正确",
+  "7009": "球幕视频文件不存在",
+  "7010": "相机或者相机详情不存在",
+  "7012": "上传的文件名错误",
+  "7013": "上传失败",
+  "7015": "仅支持 zip 文件上传",
+  "7016": "仅支持 mp4 格式文件",
+  "7018": "压缩包内请勿包含文件夹",
+  "-3": "缺少必要参数",
+  "-4": "跨服务请求失败",
+  "-5": "系统繁忙,请稍后再试",
+  "none": "未知错误"
+}
+
 
 export * from './url'
 
@@ -14,6 +53,12 @@ export const Alova = createAlova({
   timeout: 3000,
   cacheFor: null,
   cacheLogger: process.env.NODE_ENV === 'development',
+  beforeRequest(method) {
+    const token = localStorage.getItem('token')
+    if (token) {
+      method.config.headers.token = token
+    }
+  },
   responded: {
     onSuccess: async (response, method) => {
       const res = (response.json && (await response.json())) || response.body
@@ -23,7 +68,7 @@ export const Alova = createAlova({
         return res
       }
       // 请根据自身情况修改数据结构
-      const { message: info, code, data } = res
+      const { message, code, data } = res
 
       // 不进行任何处理,直接返回
       // 用于需要直接获取 code、result、 message 这些信息时开启
@@ -35,9 +80,13 @@ export const Alova = createAlova({
       if (code === 0) {
         return data
       } else {
-
-        // console.log('Message',Message)
-        message.error('代号错误 :' + code)
+        dialog.warning({
+          closable:false,
+          closeOnEsc: false,
+          maskClosable: false,
+          content: statusCode[code] || message || '加载失败'
+        })
+        return false
       }
     }
   }

+ 7 - 0
src/api/module/editor.ts

@@ -14,6 +14,13 @@ export const getInfo = (num: string) => {
     }
   })
 }
+
+export const getAuth = (num: string) => {
+  var form = new FormData()
+  form.append('num',num)
+  return Alova.Post(url.getAuth,form)
+}
+
 export const editorSave = (params: EditorSaveParams) => {
   return Alova.Post(url.editorSave, {
     ...params

+ 2 - 1
src/api/url.ts

@@ -9,7 +9,8 @@ const url = {
   messageDel: '/service/scene/edit/scrb/leaveWord/delete',
   messageAudit: '/service/scene/edit/scrb/leaveWord/audit',
   editorSave: '/service/scene/edit/scrb/save',
-  getInfo: '/service/scene/getInfo'
+  getInfo: '/service/scene/getInfo',
+  getAuth: '/service/scene/edit/getAuth'
 }
 
 export { url }

+ 7 - 1
src/store/main.ts

@@ -1,5 +1,5 @@
 import { defineStore } from 'pinia'
-import { getInfo } from '@/api/module/editor'
+import { getAuth, getInfo } from '@/api/module/editor'
 // import { watch } from 'vue'
 
 // useStore could be anything like useUser, useCart
@@ -89,6 +89,11 @@ export const useMainStore = defineStore('main', {
       this.sceneCode = m
     },
     async getSceneInfo() {
+
+      const auth = await getAuth(this.sceneCode)
+      if (auth === false) {
+        return false
+      }
       const data = await getInfo(this.sceneCode)
       console.log('data', data)
 
@@ -118,6 +123,7 @@ export const useMainStore = defineStore('main', {
           this.basicConfig = this.sceneInfo.scrbInfo.baseSetting
         }
       }
+      return data
     },
     syncNavigation(navigation: any[]) {
       this.navigation = navigation as any as []

+ 1 - 1
vite.config.ts

@@ -52,7 +52,7 @@ export default defineConfig(({ mode }) => {
         statements: 80
       }
     },
-    publicDir:"",
+    base: mode == 'development'?'':'extend',
     build: {
       sourcemap: mode === 'production' ? false : 'inline'
     },