Pārlūkot izejas kodu

增加搜索功能

flyzto 2 mēneši atpakaļ
vecāks
revīzija
57a8ec86aa

+ 18 - 3
server/models/GamesPs.js

@@ -82,6 +82,21 @@ const getRuleType = (rule) => {
   return IOR_KEYS_TYPE[rulePrefix];
 }
 
+/**
+ * 关键词匹配比赛
+ */
+const matchGame = (relation, sk) => {
+  const keys = [];
+  Object.keys(relation).forEach(platform => {
+    const { leagueName, teamHomeName, teamAwayName } = relation[platform];
+    if (platform == 'ps') {
+      keys.push(leagueName);
+    }
+    keys.push(teamHomeName, teamAwayName);
+  });
+  return keys.some(key => key.includes(sk));
+}
+
 /**
  * 同步联赛列表
  */
@@ -857,7 +872,7 @@ const getSolutions = async ({ win_min, with_events, mk=-1 }) => {
 /**
  * 获取中单方案并按照比赛分组
  */
-const getGamesSolutions = async ({ win_min, with_events, mk=-1, tp=0 }) => {
+const getGamesSolutions = async ({ win_min, with_events, mk=-1, tp=0, sk }) => {
 
   const filterMarketType = +mk;
   const filterDataType = +tp;
@@ -890,12 +905,12 @@ const getGamesSolutions = async ({ win_min, with_events, mk=-1, tp=0 }) => {
 
   const gamesSolutions = Object.values(solutionsMap)
   .filter(item => {
-    const { mk, solutions } = item;
+    const { mk, rel, solutions } = item;
     const marketType = getMarketType(mk);
     mkCount.all ++;
     mkCount[marketType] ++;
     solutions.sort((a, b) => b.sol.win_average - a.sol.win_average);
-    return filterMarketType == -1 || filterMarketType == mk;
+    return filterMarketType == -1 || filterMarketType == mk && !sk || matchGame(rel, sk);
   })
   .sort((a, b) => b.solutions[0].sol.win_average - a.solutions[0].sol.win_average);
 

+ 3 - 2
server/routes/pstery.js

@@ -87,12 +87,13 @@ router.get('/get_solutions', (req, res) => {
 
 // 获取中单方案并按照比赛分组
 router.get('/get_games_solutions', (req, res) => {
-  const { win_min, with_events, mk, tp } = req.query;
+  const { win_min, with_events, mk, tp, sk } = req.query;
   Games.getGamesSolutions({
     win_min: win_min ? +win_min : undefined,
     with_events: with_events === 'true',
     mk: mk ? +mk : -1,
-    tp: tp ? +tp : 0
+    tp: tp ? +tp : 0,
+    sk: sk.trim() ? sk.trim() : undefined,
   })
   .then(gamesSolutions => {
     res.sendSuccess(gamesSolutions);

+ 36 - 7
web/apps/web-antd/src/views/match/solutions/index.vue

@@ -1,6 +1,6 @@
 <script setup>
 import { requestClient } from '#/api/request';
-import { Button, message, Form, InputNumber, RadioGroup, Radio, Drawer } from 'ant-design-vue';
+import { Button, message, Form, InputNumber, RadioGroup, Radio, Drawer, Input } from 'ant-design-vue';
 import { ref, reactive, computed, watch, onMounted, onUnmounted } from 'vue';
 import dayjs from 'dayjs';
 
@@ -20,6 +20,7 @@ const updateTimer = ref(null);
 const minProfitRate = ref(2);
 const marketType = ref(-1);
 const dataType = ref(0);
+const searchValue = ref('');
 const updateLoaderHide = ref(null);
 
 const totalProfitVisible = ref(false);
@@ -52,8 +53,9 @@ const getSolutions = async () => {
     const win_min = minProfitRate.value * 100;
     const mk = marketType.value;
     const tp = dataType.value;
+    const sk = searchValue.value.trim();
     const with_events = true;
-    const data = await requestClient.get('/pstery/get_games_solutions', { params: { win_min, mk, tp, with_events } });
+    const data = await requestClient.get('/pstery/get_games_solutions', { params: { win_min, mk, tp, sk, with_events } });
     return data;
   }
   catch (error) {
@@ -141,6 +143,16 @@ const getLocalStorage = (key) => {
   return value ? JSON.parse(value) : null;
 }
 
+watch(searchValue, (newVal, oldVal) => {
+  if (newVal.trim() == oldVal.trim()) {
+    return;
+  }
+  clearTimeout(updateTimer.value);
+  updateTimer.value = setTimeout(() => {
+    updateSolutions();
+  }, 1000);
+});
+
 watch(minProfitRate, (newVal) => {
   clearTimeout(updateTimer.value);
   updateTimer.value = setTimeout(() => {
@@ -218,8 +230,11 @@ onUnmounted(() => {
               <Radio :value="2">大小</Radio>
             </RadioGroup>
           </Form.Item>
-          <Form.Item label="最小利润率(%)" class="sol-opt-item">
-            <InputNumber style="width: 60px" size="small" max="100" min="-100" step="0.1" placeholder="最小利润率(%)" v-model:value="minProfitRate"/>
+          <Form.Item label="最小利润率(%)" class="sol-opt-item input-item">
+            <InputNumber class="number-input" size="small" max="100" min="-100" step="0.1" placeholder="最小利润率(%)" v-model:value="minProfitRate"/>
+          </Form.Item>
+          <Form.Item class="sol-opt-item input-item">
+            <Input class="search-input" placeholder="搜索" :allowClear="true" v-model:value="searchValue"/>
           </Form.Item>
         </Form>
       </div>
@@ -278,9 +293,23 @@ onUnmounted(() => {
     margin-inline-start: auto;
   }
   &:nth-child(n+3) {
-  padding-inline-start: 15px;
-  border-left: 1px solid hsl(var(--border));
-}
+    padding-inline-start: 15px;
+    border-left: 1px solid hsl(var(--border));
+  }
+  &.input-item:not(:last-child) {
+    padding-inline-end: 15px;
+  }
+  .search-input, .number-input {
+    height: 28px;
+  }
+  .search-input {
+    width: 150px;
+  }
+  .number-input {
+    display: inline-flex;
+    width: 60px;
+    align-items: center;
+  }
 }
 
 .solution-header {