leagues.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <script setup>
  2. import { ref, reactive, computed, watch, onMounted, onUnmounted } from 'vue';
  3. import { message } from 'ant-design-vue';
  4. import { ReloadOutlined, PlusOutlined, LinkOutlined, DisconnectOutlined } from '@ant-design/icons-vue';
  5. import api from '@/libs/api';
  6. const search = ref('');
  7. const leagues = ref(null);
  8. const leaguesRelations = ref([]);
  9. const selectedLeagues = reactive({
  10. polymarket: null,
  11. pinnacle: null,
  12. });
  13. const onSearch = (value) => {
  14. search.value = value;
  15. };
  16. const updateLeagues = () => {
  17. api.get('/api/games/get_leagues').then(res => {
  18. if (res.data.statusCode === 200) {
  19. leagues.value = res.data.data;
  20. }
  21. else {
  22. throw new Error(res.data.message);
  23. }
  24. })
  25. .catch(err => {
  26. message.error(err.response?.data?.message ?? err.message);
  27. console.error(err);
  28. });
  29. };
  30. const selectLeague = (type, league) => {
  31. const { id, name } = league;
  32. const currentLeagues = { id, name };
  33. if (type === 'polymarket') {
  34. if (selectedLeagues.polymarket?.id === id) {
  35. selectedLeagues.polymarket = null;
  36. }
  37. else {
  38. selectedLeagues.polymarket = currentLeagues;
  39. }
  40. }
  41. else if (type === 'pinnacle') {
  42. if (selectedLeagues.pinnacle?.id === id) {
  43. selectedLeagues.pinnacle = null;
  44. }
  45. else {
  46. selectedLeagues.pinnacle = currentLeagues;
  47. }
  48. }
  49. else {
  50. throw new Error('invalid type');
  51. }
  52. }
  53. const resetSelectedLeagues = () => {
  54. selectedLeagues.polymarket = null;
  55. selectedLeagues.pinnacle = null;
  56. }
  57. const setLeaguesRelation = () => {
  58. if (!selectedLeagues.polymarket || !selectedLeagues.pinnacle) {
  59. message.error('请选择要添加的联赛');
  60. return;
  61. }
  62. const leagueRelation = {
  63. id: selectedLeagues.polymarket.id,
  64. platforms: selectedLeagues,
  65. };
  66. api.post('/api/games/set_leagues_relation', leagueRelation)
  67. .then(res => {
  68. if (res.data.statusCode === 200) {
  69. message.success('添加成功');
  70. }
  71. else {
  72. throw new Error(res.data.message);
  73. }
  74. refresh();
  75. resetSelectedLeagues();
  76. })
  77. .catch(err => {
  78. message.error(err.response?.data?.message ?? err.message);
  79. console.error(err);
  80. });
  81. };
  82. const removeLeaguesRelation = (relation) => {
  83. api.post('/api/games/remove_leagues_relation', { id: relation.id })
  84. .then(res => {
  85. if (res.data.statusCode === 200) {
  86. message.success('删除成功');
  87. }
  88. else {
  89. throw new Error(res.data.message);
  90. }
  91. refresh();
  92. })
  93. .catch(err => {
  94. message.error(err.response?.data?.message ?? err.message);
  95. console.error(err);
  96. });
  97. }
  98. const getLeaguesRelations = () => {
  99. api.get('/api/games/get_leagues_relations')
  100. .then(res => {
  101. if (res.data.statusCode === 200) {
  102. leaguesRelations.value = res.data.data;
  103. }
  104. else {
  105. throw new Error(res.data.message);
  106. }
  107. })
  108. .catch(err => {
  109. message.error(err.response?.data?.message ?? err.message);
  110. console.error(err);
  111. });
  112. };
  113. const refresh = () => {
  114. updateLeagues();
  115. getLeaguesRelations();
  116. }
  117. const getLeagues = (platform) => {
  118. const searchValue = search.value.trim().toLowerCase();
  119. return leagues.value?.[platform].map(item => {
  120. const { id } = item;
  121. let selected = false;
  122. let disabeld = false;
  123. if (selectedLeagues[platform]?.id === id) {
  124. selected = true;
  125. }
  126. if (leaguesRelations.value.some(relation => relation.platforms[platform]?.id === id)) {
  127. disabeld = true;
  128. }
  129. return { ...item, selected, disabeld };
  130. }).filter(item => {
  131. const { name, localesName='', sport='' } = item;
  132. return !searchValue || name.toLowerCase().includes(searchValue) || localesName.toLowerCase().includes(searchValue) || sport.toLowerCase().includes(searchValue);
  133. }) ?? [];
  134. }
  135. const polymarketLeagues = computed(() => {
  136. return getLeagues('polymarket');
  137. });
  138. const pinnacleLeagues = computed(() => {
  139. return getLeagues('pinnacle');
  140. });
  141. const leaguesRelationsFiltered = computed(() => {
  142. const searchValue = search.value.trim().toLowerCase();
  143. return leaguesRelations.value.filter(item => {
  144. const { platforms: { polymarket, pinnacle } } = item;
  145. return !searchValue
  146. || polymarket.localesName?.toLowerCase().includes(searchValue)
  147. || polymarket.name?.toLowerCase().includes(searchValue)
  148. || pinnacle.name?.toLowerCase().includes(searchValue);
  149. }) ?? [];
  150. });
  151. onMounted(() => {
  152. // console.log('leagues mounted');
  153. refresh();
  154. });
  155. onUnmounted(() => {
  156. // console.log('leagues unmounted');
  157. });
  158. </script>
  159. <template>
  160. <a-page-header title="联赛">
  161. <template #extra>
  162. <a-input-search
  163. v-model:value="search"
  164. placeholder="搜索"
  165. :allowClear="true"
  166. @search="onSearch"
  167. />
  168. <a-button @click="refresh">
  169. <template #icon>
  170. <reload-outlined />
  171. </template>
  172. 刷新
  173. </a-button>
  174. <a-button type="primary" @click="setLeaguesRelation">
  175. <template #icon>
  176. <plus-outlined />
  177. </template>
  178. 添加
  179. </a-button>
  180. </template>
  181. </a-page-header>
  182. <div class="leagues-container">
  183. <div class="leagues-column polymarket">
  184. <h3>Polymarket 联赛 ({{ polymarketLeagues.length }})</h3>
  185. <a-list item-layout="horizontal" :data-source="polymarketLeagues" size="small">
  186. <template #renderItem="{ item }">
  187. <a-list-item :class="{ selected: item.selected, disabled: item.disabeld }" @click="!item.disabeld && selectLeague('polymarket', item)">
  188. {{ item.localesName }} <em>{{ item.name }} {{ item.sport ? `[${item.sport.toUpperCase()}]` : '' }}</em>
  189. </a-list-item>
  190. </template>
  191. </a-list>
  192. </div>
  193. <div class="leagues-column pinnacle">
  194. <h3>Pinnacle 联赛 ({{ pinnacleLeagues.length }})</h3>
  195. <a-list item-layout="horizontal" :data-source="pinnacleLeagues" size="small">
  196. <template #renderItem="{ item }">
  197. <a-list-item :class="{ selected: item.selected, disabled: item.disabeld }" @click="!item.disabeld && selectLeague('pinnacle', item)">
  198. {{ item.name }}
  199. </a-list-item>
  200. </template>
  201. </a-list>
  202. </div>
  203. <div class="leagues-column relations">
  204. <h3>已添加的联赛 ({{ leaguesRelationsFiltered.length }})</h3>
  205. <a-list item-layout="horizontal" :data-source="leaguesRelationsFiltered" size="small">
  206. <template #renderItem="{ item }">
  207. <a-list-item>
  208. <div class="league-name polymarket-name">{{ item.platforms.polymarket.localesName }} <em>{{ item.platforms.polymarket.name }}</em></div>
  209. <a-button class="remove-button" type="link" @click="removeLeaguesRelation(item)">
  210. <template #icon>
  211. <link-outlined />
  212. <disconnect-outlined />
  213. </template>
  214. </a-button>
  215. <div class="league-name pinnacle-name">{{ item.platforms.pinnacle.name }}</div>
  216. </a-list-item>
  217. </template>
  218. </a-list>
  219. </div>
  220. </div>
  221. </template>
  222. <style lang="scss" scoped>
  223. .leagues-container {
  224. display: flex;
  225. flex-direction: row;
  226. justify-content: space-between;
  227. align-items: stretch;
  228. height: calc(100vh - 126px);
  229. padding: 15px;
  230. gap: 15px;
  231. border-top: 1px solid rgba(5, 5, 5, 0.06);
  232. }
  233. .leagues-column {
  234. overflow: auto;
  235. flex: 1;
  236. h3 {
  237. height: 39px;
  238. margin: 0;
  239. line-height: 39px;
  240. text-align: center;
  241. font-size: 14px;
  242. font-weight: 600;
  243. border: 1px solid rgba(5, 5, 5, 0.06);
  244. border-bottom: none;
  245. border-radius: 8px 8px 0 0;
  246. background-color: #fafafa;
  247. }
  248. }
  249. .leagues-column.relations {
  250. flex: 2.5;
  251. border-right: 0 none;
  252. }
  253. .ant-list {
  254. max-height: calc(100vh - 196px);
  255. overflow: auto;
  256. border: 1px solid rgba(5, 5, 5, 0.06);
  257. border-radius: 0 0 8px 8px;
  258. }
  259. .ant-list-item {
  260. &:hover {
  261. background-color: #fafafa;
  262. .remove-button {
  263. visibility: visible;
  264. }
  265. }
  266. &.selected {
  267. background-color: #e6f7ff;
  268. }
  269. &.disabled {
  270. opacity: 0.5;
  271. cursor: not-allowed;
  272. }
  273. .league-name {
  274. flex: 1;
  275. }
  276. .pinnacle-name {
  277. text-align: right;
  278. }
  279. .remove-button {
  280. visibility: hidden;
  281. .anticon-disconnect {
  282. display: none;
  283. }
  284. &:hover {
  285. color: #f5222d;
  286. .anticon-link {
  287. display: none;
  288. }
  289. .anticon-disconnect {
  290. margin-inline-start: 0;
  291. display: inline-block;
  292. }
  293. }
  294. }
  295. em {
  296. font-style: normal;
  297. font-size: 12px;
  298. }
  299. }
  300. </style>