index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <script setup>
  2. import { ref, watch, onMounted } from 'vue';
  3. import { requestClient } from '#/api/request';
  4. import { Page } from '@vben/common-ui';
  5. import { Form, Input, RadioGroup, Radio, Button, message } from 'ant-design-vue';
  6. import dayjs from 'dayjs';
  7. import VueJsonPretty from 'vue-json-pretty';
  8. import 'vue-json-pretty/lib/styles.css';
  9. const currentTime = ref('');
  10. const gamesRelation = ref([]);
  11. const gamesSolution = ref({});
  12. const selectedTestMode = ref(-1);
  13. const idsText = ref('');
  14. const idsList = ref([]);
  15. const buttonDisabled = ref(false);
  16. const prettyData = ref(null);
  17. const prettyKey = ref(Date.now());
  18. const dataCount = ref('');
  19. watch(selectedTestMode, () => {
  20. refreshData();
  21. });
  22. const updateTime = () => {
  23. currentTime.value = new Date().toLocaleString('zh-CN');
  24. }
  25. const idsInput = (value) => {
  26. idsList.value = idsText.value.split(',').map(item => +item.trim()).filter(item => !!item);
  27. }
  28. const refreshData = () => {
  29. buttonDisabled.value = true;
  30. updateTime();
  31. const win_min = -99999;
  32. const no_events = true;
  33. const mk = selectedTestMode.value;
  34. Promise.all([
  35. requestClient.get('/pstery/get_games_relation', { params: { mk } }),
  36. requestClient.get('/pstery/get_solutions', { params: { win_min, no_events, mk } })
  37. ])
  38. .then(([relations, solutions]) => {
  39. gamesRelation.value = relations;
  40. gamesSolution.value = solutions;
  41. prettyData.value = null;
  42. dataCount.value = '';
  43. message.success('数据已刷新');
  44. console.log('数据已刷新');
  45. })
  46. .catch(err => {
  47. message.error('数据刷新失败');
  48. console.error('数据刷新失败', err);
  49. })
  50. .finally(() => {
  51. buttonDisabled.value = false;
  52. });
  53. }
  54. const showDataPretty = (data, deep) => {
  55. prettyData.value = data;
  56. prettyKey.value = Date.now();
  57. }
  58. const runTest = (hasSolutions=true) => {
  59. const gamesList = gamesRelation.value.map(item => {
  60. const { mk } = item ?? {};
  61. const { eventId, leagueName, teamHomeName, teamAwayName, timestamp } = item?.rel?.ps ?? {};
  62. const datetime = dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss');
  63. return { eventId, leagueName, teamHomeName, teamAwayName, datetime, mk };
  64. });
  65. gamesSolution.value.solutions.forEach((solution) => {
  66. const { sid, info: { id }} = solution;
  67. const currentGame = gamesList.find(game => game.eventId === id);
  68. if (!currentGame) {
  69. console.log('game not found', id);
  70. }
  71. else {
  72. if (!currentGame.solutions) {
  73. currentGame.solutions = [];
  74. }
  75. currentGame.solutions.push(sid);
  76. }
  77. });
  78. const dataList = gamesList.filter(item => {
  79. if (hasSolutions) {
  80. return !!item.solutions?.length;
  81. }
  82. else {
  83. return !item.solutions?.length;
  84. }
  85. }).map((item, index) => {
  86. const serial = index + 1;
  87. return { serial, ...item };
  88. });
  89. dataCount.value = `${dataList.length} / ${gamesList.length}`;
  90. showDataPretty(dataList, 2);
  91. console.log('gamesRelation', dataList);
  92. }
  93. const filterLive = () => {
  94. const solutions = gamesSolution.value.solutions;
  95. const liveSolutions = solutions.filter((solution) => {
  96. const { info: { ob, hg, ps } } = solution;
  97. return ps.stage;
  98. });
  99. dataCount.value = `${liveSolutions.length}`;
  100. showDataPretty(liveSolutions, 2);
  101. console.log('liveSolutions', liveSolutions);
  102. }
  103. const filterHalf = () => {
  104. const solutions = gamesSolution.value.solutions;
  105. const halfSolutions = solutions.filter((solution) => {
  106. const { info: { ob, hg, ps } } = solution;
  107. return ps.stage === 'HT';
  108. });
  109. dataCount.value = `${halfSolutions.length}`;
  110. showDataPretty(halfSolutions, 2);
  111. console.log('halfSolutions', halfSolutions);
  112. }
  113. const filterTarget = () => {
  114. requestClient.get('/pstery/get_games_relation', { params: { mk: selectedTestMode.value, le: true, id: idsText.value } })
  115. .then(data => {
  116. dataCount.value = `${data.length}`;
  117. showDataPretty(data, 2);
  118. console.log('data', data);
  119. })
  120. .catch(err => {
  121. message.error('数据获取失败');
  122. console.error('数据获取失败', err);
  123. })
  124. }
  125. onMounted(() => {
  126. refreshData();
  127. })
  128. </script>
  129. <template>
  130. <Page title="数据测试" description="用于测试和验证比赛数据的页面">
  131. <Form :label-col="{ span: 2 }" :wrapper-col="{ span: 14 }">
  132. <Form.Item label="数据源:">
  133. <span>比赛管理系统</span>
  134. </Form.Item>
  135. <Form.Item label="更新时间:">
  136. <span>{{ currentTime }}</span>
  137. </Form.Item>
  138. <Form.Item label="测试模式:">
  139. <RadioGroup v-model:value="selectedTestMode">
  140. <Radio :value="-1">全部</Radio>
  141. <Radio :value="2">滚球</Radio>
  142. <Radio :value="1">今日</Radio>
  143. <Radio :value="0">早盘</Radio>
  144. </RadioGroup>
  145. </Form.Item>
  146. <Form.Item label="目标赛事ID:">
  147. <Input v-model:value="idsText" placeholder="请输入赛事ID,多个ID用逗号分隔" @input="idsInput" />
  148. </Form.Item>
  149. <Form.Item :wrapper-col="{ span: 14, offset: 2 }">
  150. <Button @click="refreshData" :disabled="buttonDisabled">
  151. 刷新数据
  152. </Button>
  153. <Button @click="runTest(true)" :disabled="buttonDisabled">
  154. 有欢乐值
  155. </Button>
  156. <Button @click="runTest(false)" :disabled="buttonDisabled">
  157. 无欢乐值
  158. </Button>
  159. <Button @click="filterLive" :disabled="buttonDisabled">
  160. 筛选滚球
  161. </Button>
  162. <Button @click="filterHalf" :disabled="buttonDisabled">
  163. 筛选中场
  164. </Button>
  165. <Button @click="filterTarget" :disabled="!idsList.length">
  166. 目标赛事
  167. </Button>
  168. </Form.Item>
  169. </Form>
  170. <div class="data-table" v-if="prettyData">
  171. <div class="data-count" v-if="dataCount">
  172. <span>数据总数:{{ dataCount }}</span>
  173. </div>
  174. <vue-json-pretty :data="prettyData" :indent="2" :deep="2" :key="prettyKey" :showDoubleQuotes="false"></vue-json-pretty>
  175. </div>
  176. </Page>
  177. </template>
  178. <style lang="scss" scoped>
  179. .data-table {
  180. padding: 20px;
  181. }
  182. </style>