Bladeren bron

feat: rule = 7 完成

lvkun996 8 maanden geleden
bovenliggende
commit
fa02857535
5 gewijzigde bestanden met toevoegingen van 76 en 40 verwijderingen
  1. 2 2
      config/proxy.ts
  2. 46 10
      src/controller/CardController.ts
  3. 1 1
      src/pages/card/components/game-stage-3.vue
  4. 26 26
      src/pages/card/index.vue
  5. 1 1
      src/typeing.d.ts

+ 2 - 2
config/proxy.ts

@@ -6,8 +6,8 @@
 module.exports = {
   dev: {
     '/api': {
-      target: 'http://192.168.1.198:9098/xiaodou-ai-admin/admin',
-      // target: 'http://localhost:9098/xiaodou-ai-admin/admin',
+      // target: 'http://192.168.1.198:9098/xiaodou-ai-admin/admin',
+      target: 'http://localhost:9098/xiaodou-ai-admin/admin',
       changeOrigin: true,
       pathRewrite: { '^/api': '' }
     }

+ 46 - 10
src/controller/CardController.ts

@@ -60,6 +60,20 @@ export class CardController {
     return { data: data }
   }
 
+  static async cardJsonById (id: string) {
+    const { data } = await getCardJsonById(id)
+
+    const dataJson = JSON.parse(data)
+
+    if (dataJson.header.card_type === 5) {
+      return CardController.card5JsonById(dataJson)
+    } else if (dataJson.header.card_type === 21) {
+      return CardController.card21JsonById(dataJson)
+    } else {
+      throw new Error('不支持的卡片类型')
+    }
+  }
+
   /**
    *
    * @description 根据id获取卡片json
@@ -71,10 +85,8 @@ export class CardController {
    * selected字段代表是否选择, 存在music_name是 selected是true 否则为false
    *
    */
-  static async card5JsonById (id: string) {
-    const { data } = await getCardJsonById(id)
-
-    const dataJson = JSON.parse(data) as API.CardJson
+  static async card5JsonById (_dataJson: API.CardJson) {
+    const dataJson = JSON.parse(JSON.stringify(_dataJson)) as API.CardJson
 
     (dataJson as API.CardJson).touch_key = (dataJson as API.CardJson).touch_key.map((item, index) => {
       if ('music_name' in item) {
@@ -95,15 +107,38 @@ export class CardController {
       }
     })
 
-    return { data: dataJson }
+    return { data: dataJson, cardType: dataJson.header.card_type }
   }
 
-  static async card21JsonById (id:string) {
-    const { data } = await getCardJsonById(id)
-
-    const dataJson = JSON.parse(data) as API.CardJson21
+  static async card21JsonById (_dataJson: API.CardJson21) {
+    const dataJson = JSON.parse(JSON.stringify({
+      header:
+      {
+        card_type: 21,
+        card_insert: { is_break: 3, music_name: 'yx3.mp3' },
+        card_remove: { is_break: 1 },
+        finish: { is_break: 3, music_name: 'wctk.mp3' },
+        grade: 1,
+        title: { is_break: 1, page: 293 }
+      },
+      game_list: [
+        // {
+        //   has_click_group: { is_break: 1, music_name: 'zzdg.mp3' },
+        //   has_click_single: { is_break: 1, music_name: 'yjdg.mp3' },
+        //   main_subject: { is_break: 3, music_name: '293tg.mp3' },
+        //   multiple_err: { is_break: 1 },
+        //   ordered_multiple_err: { is_break: 1, music_name: 'yxcw.mp3' },
+        //   rule: 7,
+        //   still_have: { is_break: 3, music_name: 'hmwc.mp3' },
+        //   touch_key: [[{ is_break: 3, value: 0 }], [{ is_break: 3, value: 0 }], [{ is_break: 3, value: 0 }]],
+        //   wait_30s: { is_break: 1, music_name: 'dtdd.mp3' },
+        //   wait_90s: { is_break: 1, music_name: 'dtdd.mp3' },
+        //   items: [{ sub_subject: { music_name: '100tg.mp3', mb: 1, ok: '', ob: 1, err: '', eb: 1 }, ok_key: [{ value: 4, music_name: '100tm2.mp3', is_break: 1, select: true }], err_key: [], ok_key_voice: {}, err_key_voice: {} }]
+        // }
+      ]
+    }))
     console.log('卡片是21时返回的参数', dataJson)
-    return { data: CardController.itemsToSteps(dataJson) }
+    return { data: CardController.itemsToSteps(dataJson), cardType: dataJson.header.card_type }
   }
 
   static createRectByIndex (index: number) {
@@ -184,6 +219,7 @@ export class CardController {
   // 把json中items下其他项解析到steps
   static itemsToSteps (data: API.CardJson21) {
     const newData = JSON.parse(JSON.stringify(data))
+    console.log('解析items', newData)
 
     newData.game_list.forEach((game: any) => {
       if (game.rule === 7) {

+ 1 - 1
src/pages/card/components/game-stage-3.vue

@@ -27,7 +27,7 @@
               <span>音频: <strong>{{ element.audio_name }}</strong></span>
             </div>
           </div>
-          <div class="step-actions">0
+          <div class="step-actions">
             <a-popconfirm
               title="确定要删除这个步骤吗?"
               ok-text="确定"

+ 26 - 26
src/pages/card/index.vue

@@ -137,6 +137,8 @@ const operationTip = `
 
 const cardInfo = useRoute().query as unknown as API.Card
 
+const cardTye = ref<5 | 21>()
+
 const openState = reactive({
   configCardOpen: false,
   configGameOpen: false,
@@ -275,40 +277,38 @@ const handleOperation = ({ ids }: {ids: number[]}) => {
   })
 }
 
-const getCardJson5 = async () => {
-  const { data } = await CardController.card5JsonById(cardInfo.id!)
-  cardJson.header = data.header
-  cardJson.slide_knob = data.slide_knob
-  cardJson.touch_key = data.touch_key
-
-  isValids.buttonIsValid = true
-  isValids.cardIsValid = true
+const getCardJsonById = async () => {
+  const { data, cardType: type } = await CardController.cardJsonById(cardInfo.id!)
+  cardTye.value = type
+  if (type === 5) {
+    cardJson.header = data.header
+    cardJson.slide_knob = data.slide_knob
+    cardJson.touch_key = data.touch_key
 
-  Object.keys(data.slide_knob!).forEach(key => {
-    if (key.startsWith('score') && !data.slide_knob![key]) {
-      isValids.buttonIsValid = false
-    }
-  })
-
-  data.touch_key!.forEach(item => {
-    if (item.selected && !item.music_name) {
-      isValids.cardIsValid = false
-    }
-  })
-}
+    isValids.buttonIsValid = true
+    isValids.cardIsValid = true
 
-const getCardJson21 = async () => {
-  const { data } = await CardController.card21JsonById(cardInfo.id!)
-  console.log('获取到的卡片数据:', data)
+    Object.keys(data.slide_knob!).forEach(key => {
+      if (key.startsWith('score') && !data.slide_knob![key]) {
+        isValids.buttonIsValid = false
+      }
+    })
 
-  cardJson21.header = data.header as API.CardJson21.header
-  cardJson21.game_list = data.game_list as any
+    data.touch_key!.forEach(item => {
+      if (item.selected && !item.music_name) {
+        isValids.cardIsValid = false
+      }
+    })
+  } else {
+    cardJson21.header = data.header as API.CardJson21.header
+    cardJson21.game_list = data.game_list as any
+  }
 }
 
 function onBack () { window.history.back() }
 
 onMounted(() => {
-  Number(cardInfo.card_type) === 5 ? getCardJson5() : getCardJson21()
+  getCardJsonById()
   console.log('卡片类型', cardInfo.card_type)
 })
 </script>

+ 1 - 1
src/typeing.d.ts

@@ -53,7 +53,7 @@ declare namespace API {
     state: 'stopped' | 'playing' | 'paused'
   }
 
-  type is_break = 0 | 1 | 2
+  type is_break = 0 | 1 | 2 | 3
 
   type Btn_select = 'G' | 'R' | 'P' | 'T' | 'B' | 'Y'