index.vue 5.9 KB

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