交易所前端蓝色ui 4.5 jiem
jhzh
2025-05-19 c5487881d04780e03f4dd86ed1606c587f2c7952
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
<template>
  <div>
    <div class="perpeCreateOrder" style="background: #1a1a1a">
      <!-- 开仓+ 平仓 -->
      <div class="titles">
        <span
          v-for="(item, index) in title"
          :key="index"
          :class="{ active: isActive == index }"
          @click="changeTitle(item, index)"
          >{{ item }}</span
        >
      </div>
      <!-- 全仓+杠杆 -->
      <div class="crossSettingBox">
        <div class="crossSettingItem" style="margin-right: 20px">
          {{ $t("message.home.quancang") }}
        </div>
        <div
          class="crossSettingItem"
          :style="{
            cursor:
              isActive == 0 && origin_lever.length > 1
                ? 'pointer'
                : 'not-allowed',
          }"
        >
          <div @click="openLeverDialog">
            <span> {{ current_lever_rate }}</span
            ><i class="icon iconfont icon-Mul_triangle lever-icon"></i>
          </div>
        </div>
      </div>
      <!-- 限价+市价 -->
      <el-tabs
        v-model="activeName"
        v-if="existToken"
        @tab-click="handleTabClick"
      >
        <el-tab-pane :label="$t('message.home.xianjia')" name="limit">
        </el-tab-pane>
        <el-tab-pane :label="$t('message.home.shijia')" name="opponent">
        </el-tab-pane>
      </el-tabs>
      <!-- 下单 -->
      <div class="place-order-form-box">
        <div class="common-form-box" id="leftPoForm">
          <div class="avaliable-USD">
            <div>{{ $t("message.jiaoyi.heyuezongzican") }}</div>
            <div>{{ availableMoney }} {{ unit }}</div>
          </div>
          <!-- 价格输入 -->
          <div class="place-order-input-box" v-show="activeName === 'limit'">
            <div class="input-label-box">
              {{ $t("message.home.jiage") }}
            </div>
            <div class="input-item-input">
              <div
                class="okui-input input-sm input-item-number-input input-has-value"
              >
                <div class="okui-input-box no-padding-right">
                  <input
                    inputmode="decimal"
                    max="Infinity"
                    step="0.1"
                    placeholder=""
                    name="price"
                    autocomplete="off"
                    min="0"
                    type="text"
                    class="okui-input-input"
                    v-model.number.trim="price"
                    style="transition: font-size 100ms ease 0s"
                  />
                  <span class="cols">
                    <span @click="getNewPrice">{{
                      $t("message.home.zuixinjia1")
                    }}</span>
                    {{ unit }}
                  </span>
                </div>
              </div>
            </div>
          </div>
          <!-- 张数输入 -->
          <amount-slider
            ref="sliderRef"
            :maxAmount="getVolumnByLever()"
            :closeBuyAmount="closeBuyAmount"
            :closeSellAmount="closeSellAmount"
            :symbol="newPageData.symbol"
            :lever_rate="current_lever_rate_num"
            :typeNum="isActive"
            @getAmount="getAmount"
          ></amount-slider>
          <!-- 操作按钮-->
          <div class="btns" v-if="existToken">
            <!-- 开仓显示做多买入,平仓显示平多 = 平掉做多的订单= 做空买出,平多就根据第一个订单来平张数 -->
            <div class="btn-wrapper">
              <div class="submit-btn-box">
                <button
                  side="buy"
                  type="button"
                  class="okui-btn btn-sm btn-fill-green submit-btn long"
                  @click="buyAndSell('buy')"
                >
                  <span class="btn-content">{{
                    existToken
                      ? isActive == 0
                        ? $t("message.home.kaiduo1")
                        : $t("message.home.pingduo")
                      : $t("message.home.dengluhoujiaoyi")
                  }}</span>
                </button>
              </div>
            </div>
            <!-- 做空 -->
            <div class="btn-wrapper">
              <div class="submit-btn-box">
                <button
                  side="sell"
                  type="button"
                  class="okui-btn btn-sm btn-fill-red submit-btn short"
                  @click="buyAndSell('sell')"
                >
                  <span class="btn-content">{{
                    existToken
                      ? isActive == 0
                        ? $t("message.home.kaikong1")
                        : $t("message.home.pingkong")
                      : $t("message.home.dengluhoujiaoyi")
                  }}</span>
                </button>
              </div>
            </div>
          </div>
          <!-- 提示数据 -->
          <div class="submit-info" v-if="existToken && isActive == 0">
            <!-- 合约金额=保证金-->
            <div class="submit-info-item">
              <div>{{ $t("message.home.heyuejine") }}:</div>
              <div>{{ getMargin }} {{ unit }}</div>
            </div>
            <!-- 保证金 -->
            <div class="submit-info-item">
              <div>{{ $t("message.home.baozhengjin") }}:</div>
              <div>{{ getMargins }} {{ unit }}</div>
            </div>
            <!-- 手续费 -->
            <div class="submit-info-item">
              <div>{{ $t("message.home.shouxufei") }}:</div>
              <div>{{ getFee }} {{ unit }}</div>
            </div>
          </div>
 
          <div class="noLogin" v-if="!existToken">
            <div @click="gologin(1)">{{ $t("message.home.lijizhuce") }}</div>
            <div @click="gologin(2)">{{ $t("message.home.denglu") }}</div>
          </div>
        </div>
      </div>
    </div>
    <!-- 杠杆弹窗,开仓才展示 -->
    <lever-dialog-vue
      :current_lever="current_lever_rate_num"
      ref="leverDialog"
      :symbol="newPageData.symbol"
      :lever_rate="origin_lever"
      :sessionObj="sessionObj"
      v-if="isActive == 0 && origin_lever.length > 1"
    />
    <!-- 平仓弹窗 -->
    <close-dialog
      ref="closeDialog"
      :type="activeName"
      :sellOrBuy="directionName"
      :info="getSubmitInfo('close')"
      :newPrice="newPageData.close"
    ></close-dialog>
    <!-- 开仓弹窗 -->
    <open-dialog
      ref="openDialog"
      :type="activeName"
      :sellOrBuy="directionName"
      :info="getSubmitInfo('open')"
    ></open-dialog>
  </div>
</template>
<script>
import { mapState } from "pinia";
import { useUserStore } from "@/store/user";
import Axios from "@/api/perpetualContract.js";
import closeDialog from "./orderCom/closeDialog.vue";
import openDialog from "./orderCom/openDialog.vue";
import amountSlider from "./orderCom/amountSlider.vue";
import leverDialogVue from "./orderCom/leverDialog.vue";
import bus from "vue3-eventbus";
import { ElMessage } from "element-plus";
 
export default {
  name: "perpeCreateOrder",
  props: {
    // 当前币种的信息
    pageData: {
      type: Object,
      default: function () {
        return {};
      },
    },
    unit: {
      type: String,
    },
    // 最新的价格
    clickData: {
      type: String,
    },
  },
  data() {
    return {
      title: [
        this.$t("message.home.kaicang"),
        this.$t("message.home.pingcang"),
      ],
      newPageData: {}, //替代pageData,因为不能修改props的数据
      isActive: 0, //开仓0or平仓1
      activeName: "limit", //限价or市价
      directionName: "", //buy Or sell
      price: undefined, //输入的价格
      sessionObj: {}, //
 
      //
      lever_rate: ["1.00X"], // 后端返回的杠杆 ['1.00X','2.00X',...]
      origin_lever: [], // 支持的杠杆 [1,2,3]
      current_lever_rate: "", //当前选中
      current_lever_rate_num: 1, //当前选中的杠杆数字 1
 
      initClose: {},
      initOpen: {},
      inputAmount: "0.00",
      availableMoney: "0.00",
      closeBuyAmount: 0,
      closeSellAmount: 0,
      isNewPrice: 0,
      timer: null,
    };
  },
  components: {
    leverDialogVue,
    closeDialog,
    openDialog,
    amountSlider,
  },
  mounted() {
    // 登录之后才能调用
    if (this.existToken) {
      this.initContractparams();
      this.timer = setInterval(() => {
        this.initContractparams();
      }, 2000);
    }
 
    this.price = this.newPageData.close;
 
    // 下单成功后,清除下单区数据以及初始化参数
    bus.on("cleanOrderData", () => {
      this.$refs.sliderRef?.cleanAmount();
      this.sliderAmount = undefined;
    });
    // params:type类型
    bus.on("getSesstionToken", (type) => {
      setTimeout(() => {
        this.initContractparams(type);
      }, 2000); //延迟调用
    });
    bus.on("moneyContract", (val) => {
      this.availableMoney = val;
    }); //合约可用余额
  },
  //销毁定时器
  unmounted() {
    clearInterval(this.timer);
  },
  computed: {
    ...mapState(useUserStore, ["existToken"]),
    // 开仓弹窗的信息
    getSubmitInfo: function () {
      let self = this;
      const symbol = this.$route.params.id;
      return function (type) {
        return {
          price: self.price,
          lever_rate: self.current_lever_rate_num,
          amount: self.inputAmount, //从滑块组件取值
          symbol, //当前币种
          session_token:
            type === "close"
              ? self.initClose?.session_token
              : self.initOpen?.session_token,
          volume: self.getVolumnByLever(),
        };
      };
    },
    // 获取合约金额
    getContractAmount: function () {
      const amount = this.inputAmount;
      let data = "0.00";
      if (amount != undefined && this.lever_rate != undefined) {
        if (this.lever_rate?.length > 0) {
          data = this.sessionObj?.amount * amount * this.current_lever_rate_num;
        } else if (this.lever_rate.length == 0) {
          data = this.sessionObj?.amount * amount * 1;
        }
      }
      return bigDecimal.round(data, 2);
    },
    getMargins: function () {
      const amount = this.inputAmount;
      let data = "0.00";
      if (
        this.isActive === 0 &&
        amount != undefined &&
        this.lever_rate.length != undefined &&
        this.sessionObj.amount
      ) {
        if (this.lever_rate.length > 0) {
          data = this.sessionObj.amount * amount ;
        } else if (this.lever_rate.length == 0) {
          data = this.sessionObj.amount * amount * 1;
        }
      }
      return bigDecimal.round(data, 2);
    },
    // 获取保证金,开仓才需要
    getMargin: function () {
      const amount = this.inputAmount;
      let data = "0.00";
      if (
        this.isActive === 0 &&
        amount != undefined &&
        this.lever_rate.length != undefined &&
        this.sessionObj.amount
      ) {
        if (this.lever_rate.length > 0) {
          data = this.sessionObj.amount * amount * this.current_lever_rate_num;
        } else if (this.lever_rate.length == 0) {
          data = this.sessionObj.amount * amount * 1;
        }
      }
      return bigDecimal.round(data, 2);
    },
    // 获取手续费
    getFee: function () {
      const amount = this.inputAmount;
      let data = "0.00";
      if (amount && this.isActive == 0) {
        // 每手的数量*多少手(张)*每手的手续费
        data = amount * this.current_lever_rate_num * this.sessionObj.fee;
      }
      return bigDecimal.round(data, 2);
    },
  },
  watch: {
    // 当杠杆调整之后,张数输入框以及滑块归零
    current_lever_rate(val) {
      this.$refs.sliderRef?.emptyValue();
      this.$refs.sliderRef?.cleanAmount();
      this.inputAmount = "0.00";
    },
    // 市价单,主动赋值
    clickData(val) {
      //正好处在数据没变动的时候,那就不会被赋值
      if (this.activeName == "opponent") {
        this.price = val;
      }
    },
    // 币种数据
    pageData(val) {
      this.newPageData = val;
      if (this.isNewPrice == 0) {
        this.getNewPrice();
        this.isNewPrice = this.isNewPrice + 1;
      }
    },
    "$route.params.id"(val) {
      this.initContractparams();
    },
  },
  methods: {
    //获取张数
    getAmount(val) {
      this.inputAmount = val;
    },
    // 切换限价单和市价单
    handleTabClick(tab) {
      //tab, tab.index tab.name
      this.price = this.newPageData.close;
      this.$refs.sliderRef?.cleanAmount();
      this.$refs.sliderRef?.emptyValue();
    },
    getNewPrice() {
      this.price = this.newPageData.close;
    },
    // 切换开仓和平仓
    changeTitle(item, index) {
      this.isActive = index;
      this.$refs.sliderRef?.cleanAmount();
      this.$refs.sliderRef?.emptyValue();
    },
    // 获取张数,数据转换
    getVolumnByLever() {
      let amount = this.initOpen.volume;
      if (this.isActive == 1) {
        amount = Math.max(this.closeSellAmount, this.closeBuyAmount);
      }
      if (!amount) {
        return 0;
      } else {
        if (this.lever_rate.length > 0) {
          return parseInt(amount * this.current_lever_rate_num);
        } else if (this.lever_rate.length == 0) {
          return parseInt(amount / 1);
        }
      }
    },
 
    gologin(type) {
      //  跳登录注册
      if (type == 1) {
        this.$router.push("/register");
      } else if (type == 2) {
        this.$router.push("/login");
      }
    },
    // 买卖按钮
    buyAndSell(type) {
      this.directionName = type;
      if (!this.existToken) {
        this.$router.push("/login");
      } else {
        if (!this.price) {
          const text = this.$t("message.home.qingshurujine");
          ElMessage(text);
          return;
        }
        if (!this.$refs.sliderRef?.amount) {
          const text = this.$t("message.home.qingshurushuliang");
          ElMessage(text);
          return;
        }
        if (this.isActive === 0) {
          // 开仓弹窗
          this.$refs.openDialog.open();
        } else {
          // 平仓弹窗
          this.$refs.closeDialog.open();
        }
      }
    },
    // 初始化合约
    initContractparams(type) {
      //平仓初始化参数
      const symbol = this.$route.params.id;
      if (type === "close" || !type) {
        Axios._initClose({
          symbol,
          direction: "sell",
        }).then((res) => {
          // 平仓的杠杆不能调整
          //返回数据只有session_token和amount,lever_rate
          this.initClose = res.data;
          this.closeSellAmount = res.data.amount;
        });
 
        Axios._initClose({
          symbol,
          direction: "buy",
        }).then((res) => {
          this.closeBuyAmount = res.data.amount;
        });
      }
 
      //开仓初始化参数
      if (type === "open" || !type) {
        Axios._initOpen({ symbol: this.$route.params.id }).then((res) => {
          if (res.code == "0") {
            this.initOpen = res.data;
            this.sessionObj = res.data; //展示数据都用开仓的,只有session取值不一样
            bus.emit("closeTrade", res.data?.open); //是否开仓
            const { lever } = res.data;
            const hasLever = lever && lever.length;
            if (hasLever) {
              this.lever_rate = lever.map((val) => {
                return Number(val.lever_rate).toFixed(2) + "X";
              });
 
              this.origin_lever = lever.map((val) => {
                return val.lever_rate;
              });
            }
            if (!this.current_lever_rate) {
              this.current_lever_rate = hasLever ? this.lever_rate[0] : "1.00X";
              this.current_lever_rate_num = hasLever
                ? this.origin_lever[0]
                : "1";
            }
          }
        });
      }
    },
    openLeverDialog() {
      this.$refs.leverDialog.open();
    },
    // 杠杆修改后
    changeLever(newLever) {
      const formatLever = `${newLever}.00X`;
      this.current_lever_rate = formatLever; //1.00X
      this.current_lever_rate_num = newLever;
    },
  },
};
</script>
<style lang="scss" scoped>
@import url("@/assets/css/commonTrade/perpeContract.css");
@import url("@/assets/css/commonTrade/global.css");
 
.perpeCreateOrder {
  padding: 0 12px;
}
.crossSettingBox {
  display: flex;
  justify-content: space-between;
}
.crossSettingItem {
  background: rgb(48, 49, 51);
  border-radius: 4px;
  width: 100%;
  text-align: center;
  height: 32px;
  line-height: 32px;
}
 
.btn-content {
  font-size: 13px;
}
.avaliable-USD {
  padding-top: 6px;
  display: flex;
  justify-content: space-between;
}
 
/* 以上是修改的样式 */
.titles {
  height: 42px;
  line-height: 36px;
}
.titles .active {
  color: #4373df;
  border-top: 2px solid #4373df;
}
.titles span {
  display: inline-block;
  width: 50%;
  text-align: center;
  cursor: pointer;
}
.submit-info-item {
  color: #909090;
  height: 32px;
  line-height: 32px;
  display: flex;
  justify-content: space-between;
}
 
/* 张数输入 */
.place-order-input-box {
  position: relative;
  color: #909090;
}
.place-order-input-box .input-label-box {
  position: absolute;
  top: 0px;
  left: 10px;
  display: inline-block;
  height: 30px;
  line-height: 30px;
  z-index: 9;
}
.place-order-input-box input {
  padding: 0px 10px;
  box-sizing: border-box;
  text-align: center;
}
 
.place-order-form-box .place-order-form-splitter {
  height: auto;
}
.place-order-inner-common {
  padding: 0px 16px 4px 13px;
}
.place-order-input-box .okui-input-box .cols {
  display: inline-block;
  position: absolute;
  right: 0px;
}
 
.place-order-input-box .okui-input-box .cols span {
  color: #4373df;
  padding-right: 10px;
  cursor: pointer;
}
.place-order-form-box {
  display: initial;
}
.place-order-form-box .submit-btn-box-container {
  margin-top: 0px;
}
 
/*  */
.btns {
  display: flex;
}
.btns .btn-wrapper {
  width: 50%;
  padding: 0px 5px;
  box-sizing: border-box;
  margin: 16px 0;
}
.place-order-form-box .place-order-form-splitter {
  background: none;
}
 
.noLogin div {
  width: 100%;
  height: 40px;
  line-height: 40px;
  border-radius: 5px;
  text-align: center;
  color: #fff;
}
.noLogin div:nth-child(1) {
  background: #1d91ff;
}
.noLogin div:nth-child(2) {
  background: #484d56;
  margin-top: 20px;
}
</style>