li.shaoyi 3 лет назад
Родитель
Сommit
3c379e93b7

+ 22 - 0
src/filters/index.ts

@@ -0,0 +1,22 @@
+/**
+ * 处理价格颜色的显示
+ */
+export function handlePriceColor(curValue: number, preValue: number) {
+    if (curValue === preValue) {
+        return '';
+    } else if (curValue > preValue) {
+        return 'g-color--up';
+    } else {
+        return 'g-color--down'
+    }
+}
+
+/**
+ * 处理无效值的情况
+ * @param value 值
+ * @param suffix 后缀名
+ * @returns 
+ */
+export function handleNoneValue<T>(value: T, suffix = '') {
+    return value ? value + suffix : '--';
+}

+ 2 - 0
src/packages/mobile/assets/themes/default/variable.less

@@ -12,6 +12,8 @@
     --color-secondary: #04c786;
     --color-info     : #999;
     --color-border   : #eee;
+    --color-up       : #ff2b2b;
+    --color-down     : #04c786;
 
     /* 导航栏 */
     --navbar-height          : .88rem;

+ 10 - 0
src/packages/mobile/assets/themes/style.less

@@ -34,4 +34,14 @@
         overflow-y                : auto;
         -webkit-overflow-scrolling: touch;
     }
+}
+
+.g-color {
+    &--up {
+        color: var(--color-up);
+    }
+
+    &--down {
+        color: var(--color-down);
+    }
 }

+ 39 - 6
src/packages/mobile/views/home/components/market/index.vue

@@ -2,9 +2,27 @@
   <div class="home-market g-flex">
     <app-navbar title="市场" :show-back-button="false"></app-navbar>
     <div class="home-market__container g-flex__body">
-      <Grid :column-num="3" style="margin-bottom:.2rem">
+      <Grid :column-num="3" style="margin-bottom: .2rem;">
         <GridItem icon="photo-o" text="商品" :to="{ name: 'order' }" v-for="index in 6" :key="index" />
       </Grid>
+      <table style="width: 100%;text-align: center;background-color: #fff;margin-bottom: .2rem;">
+        <tr>
+          <th style="padding: .1rem 0;">合约</th>
+          <th>最新</th>
+          <th>最高</th>
+          <th>最低</th>
+          <th>买量</th>
+          <th>卖量</th>
+        </tr>
+        <tr v-for="(item, index) in quoteList" :key="index">
+          <td style="padding: .1rem 0;">{{ item.goodscode }}</td>
+          <td :class="handlePriceColor(item.last, item.presettle)">{{ handleNoneValue(item.last) }}</td>
+          <td :class="handlePriceColor(item.highest, item.presettle)">{{ handleNoneValue(item.highest) }}</td>
+          <td :class="handlePriceColor(item.lowest, item.presettle)">{{ handleNoneValue(item.lowest) }}</td>
+          <td :class="handlePriceColor(item.bid, item.presettle)">{{ handleNoneValue(item.bidvolume) }}</td>
+          <td :class="handlePriceColor(item.ask, item.presettle)">{{ handleNoneValue(item.askvolume) }}</td>
+        </tr>
+      </table>
       <Button @click="showAction = true" plain block>更换主题</Button>
     </div>
     <ActionSheet v-model:show="showAction" :actions="actions" teleport="body" cancel-text="取消" @select="onSelect" />
@@ -12,11 +30,18 @@
 </template>
 
 <script lang="ts" setup>
-import { ref } from 'vue'
+import { ref, onActivated, onDeactivated } from 'vue'
+import { v4 } from 'uuid'
 import { Grid, GridItem, Button, ActionSheet, ActionSheetAction } from 'vant'
-import Theme from '@/hooks/theme'
+import { addSubscribe, removeSubscribe } from '@/business/quote'
+import { globalState } from '@/store'
+import { handlePriceColor, handleNoneValue } from '@/filters'
+import theme from '@/hooks/theme'
 
+const uuid = v4();
 const showAction = ref(false);
+const quoteList = globalState.getRef('quoteList');
+
 const actions: ActionSheetAction[] = [
   { name: '默认' },
   { name: '浅色' },
@@ -26,20 +51,28 @@ const actions: ActionSheetAction[] = [
 const onSelect = (action: ActionSheetAction) => {
   switch (action.name) {
     case '默认': {
-      Theme.setTheme('default');
+      theme.setTheme('default');
       break;
     }
     case '浅色': {
-      Theme.setTheme('light');
+      theme.setTheme('light');
       break;
     }
     case '深色': {
-      Theme.setTheme('dark')
+      theme.setTheme('dark')
       break;
     }
   }
   showAction.value = false;
 }
+
+onActivated(() => {
+  addSubscribe(['pp2205', 'pp2206', 'b2205', 'b2206'], uuid);
+})
+
+onDeactivated(() => {
+  removeSubscribe(uuid)
+})
 </script>
 
 <style lang="less">

+ 6 - 1
src/services/http/index.ts

@@ -91,7 +91,12 @@ export async function httpRequest<T, R>(url: string, method: Method, params: Htt
                 fail && fail(data);
         }
     }).catch((err) => {
-        console.error(err);
+        fail && fail({
+            code: -1,
+            msg: err,
+            total: 0,
+            data: undefined as unknown as R
+        });
     }).finally(() => {
         complete && complete();
     })

+ 1 - 1
src/services/socket/quote/build/decode.ts

@@ -111,7 +111,7 @@ export function parseReceivePush(quotationData: Uint8Array) {
 
                     if (Object.keys(quote).length) {
                         result.push(quote);
-                        console.log('行情推送', quote);
+                        //console.log('行情推送', quote);
                     }
                 }
             }