| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- import { getCardList, addCard, addDefaultCard, getCardJsonById, getDefaultCard } from '@/api/card'
- import { message } from 'ant-design-vue'
- export class CardController {
- static cardType = [
- { value: 5, title: '推钮卡' },
- { value: 21, title: '点触卡' }
- ]
- static ruleList = [
- { title: '单点单播', value: 7, desc: '无err_key, 只加ok_key' }, // 点一下播放一个语音,此时语音放在ok_key里
- { title: '无序多点', value: 9, desc: '单点操作,多个答案的无序单选' }, // 点完所有答案播放语音,语音放在ok_key_voice里 按照步骤
- { title: '有序单点', value: 10, desc: '单点操作,多个正确答案的有序单选' }, // 点完所有答案播放语音,语音放在ok_key_voice里 按照步骤
- // { title: '双点', value: 11, desc: '' },
- // { title: '无序多选(有一个固定按钮)', value: 12, desc: '' },
- // { title: '有序多选(有一个固定按钮)', value: 13, desc: '' },
- { title: '无序多选', value: 14, desc: '' }, // 每组有两个答案,每个答案有一个语音,语音放在ok_key_voice里 按照步骤
- { title: '有序多选', value: 15, desc: '' }, // 每组有两个答案,每个答案有一个语音,语音放在ok_key_voice里 按照步骤
- { title: 'pk对战', value: 16, desc: '' }, // ok_key下的item同时有两项语音放在ok_key_voice里 按照步骤,错误的err_key数量位置,语音放在err_key_voice里
- { title: '有序单点和无序单点混搭', value: 17, desc: '' }, // 17时order代表是有序单点还是无序单点
- { title: '新手指引', value: 18, desc: '' }
- ]
- static cardButtonTitleMap = new Map([
- [0, '按钮'],
- [1, '刷新'],
- [2, '提示']
- ])
- static cardButtonRowMap = new Map([
- [1, 'A'],
- [2, 'B'],
- [3, 'C'],
- [4, 'D'],
- [5, 'E'],
- [6, 'F']
- ])
- static breakList = [
- { value: 0, title: '能被其他音频打断,不能打断其他音频' },
- { value: 1, title: '能被其他音频打断,能打断其他音频' },
- { value: 2, title: '不能被其他音频打断,不能打断其他音频' },
- { value: 3, title: '不能被其他音频打断,能打断其他音频' }
- ]
- static breakMap = new Map([
- [0, '能被其他音频打断,不能打断其他音频'],
- [1, '能被其他音频打断,能打断其他音频'],
- [2, '不能被其他音频打断,不能打断其他音频'],
- [3, '不能被其他音频打断,能打断其他音频']
- ])
- static async getCardList (parentId: string) {
- const { data } = await getCardList(parentId)
- return { data }
- }
- static async add (data: API.CardJson) {
- const _data = data
- if (data.header.card_type === 5) {
- CardController.completeCard5Json(_data)
- }
- const { status } = await addCard(data.header.card_type, _data)
- status === 200 ? message.success('保存成功') : message.error('保存失败')
- return status
- }
- static async addDefaulJson (data: API.CardJsonDefault) {
- const { status } = await addDefaultCard(data)
- status === 200 ? message.success('保存成功') : message.error('保存失败')
- return status
- }
- static async getDefaultJson () {
- const { data } = await getDefaultCard()
- return { data: data }
- }
- static async cardJsonById (id: string) {
- const { data } = await getCardJsonById(id)
- // 没有默认数据的,需要让用户选择题卡类型
- if (data == null) {
- return { data: {}, cardType: '' }
- }
- const dataJson = JSON.parse(data)
- console.log('卡片数据详情:', dataJson)
- 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
- * @param id
- * @returns
- *
- * touch_key 和卡片的操作联系在一起,在这里手动处理参数不够的问题
- * 给touch_key增加id, name, 是否已经选择也在这里处理
- * selected字段代表是否选择, 存在music_name是 selected是true 否则为false
- *
- */
- 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 && item.music_name) {
- return {
- ...item,
- ...CardController.createRectByIndex(index),
- id: index,
- selected: true
- }
- } else {
- return {
- is_break: item.is_break,
- ...CardController.createRectByIndex(index),
- music_name: '',
- id: index,
- selected: false
- }
- }
- })
- return { data: dataJson, cardType: dataJson.header.card_type }
- }
- static async card21JsonById (_dataJson: API.CardJson21) {
- const dataJson = JSON.parse(JSON.stringify(_dataJson)) as API.CardJson21
- console.log('卡片是21时返回的参数', dataJson)
- dataJson.game_list.forEach((game: any) => {
- if (!game.touch_key || !Array.isArray(game.touch_key)) {
- game.touch_key = [
- [{ value: 0, is_break: 1, music_name: '' }],
- [{ value: 0, is_break: 1, music_name: '' }],
- [{ value: 0, is_break: 1, music_name: '' }]
- ]
- }
- game.touch_key.forEach((touch_keys: API.CardJson21TouchKey) => {
- if (
- touch_keys[0].music_name === undefined ||
- touch_keys[0].music_name === null ||
- touch_keys[0].music_name === '' ||
- !touch_keys[0].music_name
- ) {
- touch_keys[0].music_name = ''
- }
- })
- })
- return { data: dataJson, cardType: dataJson.header.card_type }
- }
- static createRectByIndex (index: number) {
- if (index < 3) {
- return {
- name: CardController.cardButtonTitleMap.get(index)!,
- col: index,
- row: 0
- }
- } else {
- const row = Math.floor((index - 2) / 6) + ((index - 2) % 6 === 0 ? 0 : 1)
- const prefix = CardController.cardButtonRowMap.get(row)!
- const suffix = (index - 2) % 6 === 0 ? 6 : (index - 2) % 6
- return {
- name: prefix + suffix,
- row: row,
- col: suffix - 1
- }
- }
- }
- static createRect () {
- const obj = [] as any[]
- for (let row = 1; row < 7; row++) {
- for (let col = 1; col < 7; col++) {
- const prefix = CardController.cardButtonRowMap.get(row)!
- const suffix = col
- obj.push({
- id: col + (row - 1) * 6,
- name: prefix + suffix,
- row: row,
- col: suffix - 1,
- music_name: '',
- is_break: 1,
- value: '',
- select: true
- })
- }
- }
- return obj
- }
- // cardtype = 5
- static generateCard5Json (): API.CardJson {
- return {
- header: {
- card_type: 5,
- title: {
- category: 0,
- id: 0,
- sub_id: 0,
- page: 0,
- music_name: '',
- is_break: 0
- },
- card_insert: { music_name: '', is_break: 1 },
- card_remove: { music_name: '', is_break: 1 },
- ack_ok: { music_name: '', is_break: 1 },
- ack_mdf: { music_name: '', is_break: 1 },
- ack_err: { music_name: '', is_break: 1 },
- remind_ack: { music_name: '', is_break: 1 },
- remind_button: { music_name: '', is_break: 1 },
- remind_not_ack: { music_name: '', is_break: 1 },
- wait_30s: { music_name: '', is_break: 1 },
- wait_90s: { music_name: '', is_break: 1 }
- },
- slide_knob: {
- score1: '',
- score2: '',
- score3: '',
- score4: '',
- score5: '',
- score6: '',
- purple: [{ music_name: '', is_break: 1, key: 'purple' }],
- red: [{ music_name: '', is_break: 1, key: 'red' }],
- green: [{ music_name: '', is_break: 1, key: 'green' }],
- tangerine: [{ music_name: '', is_break: 1, key: 'tangerine' }],
- yellow: [{ music_name: '', is_break: 1, key: 'yellow' }],
- blue: [{ music_name: '', is_break: 1, key: 'blue' }]
- },
- touch_key: new Array(39).fill(0).map((item, index) => {
- return {
- id: index,
- music_name: '',
- is_break: 1,
- ...CardController.createRectByIndex(index),
- selected: false
- }
- })
- }
- }
- static generateCard21Json (): API.CardJson21 {
- return {
- header: {
- card_type: 21,
- title: {
- category: 0,
- id: 0,
- sub_id: 0,
- page: 0,
- music_name: '',
- is_break: 1
- },
- card_insert: { music_name: '', is_break: 1 },
- card_remove: { music_name: '', is_break: 1 },
- finish: { music_name: '', is_break: 1 }
- },
- game_list: []
- }
- }
- // 用户提交json时,为保证数据的正确统一性,没填写的字段进行补全
- static completeCard5Json (dataJson: API.CardJson) {
- const card5Json = CardController.generateCard5Json()
- Object.keys(card5Json.header).forEach((key) => {
- if (dataJson.header[key] === undefined || dataJson.header[key] === null || dataJson.header[key] === '') {
- dataJson.header[key] = card5Json.header[key]
- }
- })
- // 给slide_knob赋值
- if (dataJson.slide_knob === null || dataJson.slide_knob === undefined) {
- dataJson.slide_knob = card5Json.slide_knob
- } else {
- Object.keys(card5Json.slide_knob!).forEach((key) => {
- // 给score赋值
- if (typeof card5Json.slide_knob![key] === 'string' && !dataJson.slide_knob![key]) {
- dataJson.slide_knob![key] = card5Json.slide_knob![key]
- } else {
- // 给颜色数组赋值
- if (dataJson.slide_knob![key] === undefined || dataJson.slide_knob![key] === null || dataJson.slide_knob![key].length === 0) {
- dataJson.slide_knob![key] = card5Json.slide_knob![key]
- }
- }
- })
- }
- // 给touch_key赋值
- if (dataJson.touch_key === null || dataJson.touch_key === undefined) {
- dataJson.touch_key = card5Json.touch_key
- } else {
- Object.keys(card5Json.touch_key!).forEach((key) => {
- if (dataJson.touch_key![key] === undefined || dataJson.touch_key![key] === null || dataJson.touch_key![key] === '') {
- dataJson.touch_key![key] = card5Json.touch_key![key]
- }
- })
- }
- }
- }
|