contract-miao-detail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <template>
  2. <v-page>
  3. <v-header :leftClick="() =>back()" :left-arrow="false">
  4. <template #left>
  5. <view>
  6. <van-icon name="arrow-left" />
  7. </view>
  8. <view class="fn-20 color-light m-l-xs" @click.stop="symbolListShow = true">
  9. <i class="iconfont color-theme-1">&#xe655;</i>
  10. {{ query.code }}
  11. </view>
  12. </template>
  13. <template #right>
  14. <view class="fn-lg" @click="option">
  15. <van-icon v-if="isCoolect" class="color-theme-1" name="star" />
  16. <van-icon v-else name="star-o" />
  17. </view>
  18. <!-- <v-link to="/pages/exchange/miao-record">
  19. <van-icon class="fn-20 m-t-xs" name="todo-list-o" />
  20. </v-link> -->
  21. </template>
  22. </v-header>
  23. <view class="layout-main" :style="this.clientHeigth">
  24. <view class="price-data d-flex p-t-xs p-x-md justify-between bg-panel-3 m-x-md rounded-xs">
  25. <view class="col">
  26. <view class="num fn-20 color-light">
  27. {{ activeCoin.price }}
  28. </view>
  29. <view class="d-flex">
  30. <view class="m-l-xs fn-19" :class="activeCoin.increase < 0 ? 'color-sell' : 'color-buy'">
  31. {{ activeCoin.increaseStr }}
  32. </view>
  33. </view>
  34. </view>
  35. <view class="col fn-right justify-center d-flex flex-col">
  36. <table>
  37. <tr>
  38. <td>24H {{ $t("exchange.e3") }}</td>
  39. <td class="color-light">{{ activeCoin.high }}</td>
  40. </tr>
  41. <tr>
  42. <td>24H {{ $t("exchange.e4") }}</td>
  43. <td class="color-light">{{ activeCoin.low }}</td>
  44. </tr>
  45. <tr v-if="!query.contract">
  46. <td>24H {{ $t("exchange.e5") }}</td>
  47. <td class="color-light">{{ activeCoin.vol }}</td>
  48. </tr>
  49. </table>
  50. </view>
  51. </view>
  52. <van-tabs :border="false" :active="activeTime" animated :ellipsis="false"
  53. @change="tabInterval($event.detail.name)">
  54. <van-tab v-for="item in resolutions" :name="item.value" :title="item.label" :key="item.label">
  55. </van-tab>
  56. </van-tabs>
  57. <view class="chart-box">
  58. <iframe class="chart-tradingview" :src="`${mobileBase}static/tradingview.html?${setQuery(iframeQuery)}`"
  59. frameborder="0"></iframe>
  60. </view>
  61. <van-tabs animated swipeable v-model="active" sticky :ellipsis="false" offset-top="1.22667rem">
  62. <van-tab :title="$t('miao.b1')">
  63. <miao-record ref="miaoRecord" />
  64. </van-tab>
  65. <van-tab v-if="this.query.code !== 'ABK/USDT'" :title="$t('exchange.e6')">
  66. <sale :buyList="buyList" :sellList="sellList" />
  67. </van-tab>
  68. <van-tab :title="$t('exchange.d3')">
  69. <latest-transaction :tradeList="tradeList" />
  70. </van-tab>
  71. <van-tab :title="$t('exchange.e7')">
  72. <coin-info :query="query" />
  73. </van-tab>
  74. </van-tabs>
  75. </view>
  76. <!-- 左侧的弹窗 -->
  77. <van-popup class="bg-panel-4" :show="symbolListShow" @close="symbolListShow = false" close-on-popstate
  78. position="left" custom-style="height:100%;width:70%">
  79. <symbol-list :collect="collect" :marketList="marketList" :title="query.contract ? $t('contract.a4') : ''"
  80. @check-symbol="checkSymbol" />
  81. </van-popup>
  82. <view class="btn-group footer d-flex p-md">
  83. <view class="buyBtn jybtn" @click="buyShow(1)">{{$t('miao.a2')}}</view>
  84. <view class="sellBtn jybtn" @click="buyShow(2)">{{$t('miao.a3')}}</view>
  85. </view>
  86. <!-- 买涨买跌弹窗 -->
  87. <!-- 购买的弹窗 -->
  88. <van-popup :show="buyOptShow" close-on-popstate position="bottom" custom-style="width:100%" class="option-form">
  89. <buy-option-form @success="resetWaiting" @refreshRecord="refreshRecord" @close="buyOptShow = false" :query="buyQuery" :type="buyType" />
  90. </van-popup>
  91. <van-toast id="van-toast" />
  92. </v-page>
  93. </template>
  94. <script>
  95. import sale from "./sale";
  96. import miaoRecord from "./miao-record"
  97. import symbolList from "./symbol-list";
  98. import latestTransaction from "./latest-transaction";
  99. import coinInfo from "./coin-info";
  100. import Market from "@/api/market";
  101. import Contract from "@/api/contract";
  102. import Home from "@/api/home";
  103. import {
  104. mapState
  105. } from "vuex";
  106. import math from "@/utils/class/math";
  107. import Exchange from "@/api/exchange";
  108. import buyOptionForm from "./buy-option-form";
  109. import qs from "qs";
  110. import app from "app.js";
  111. // 所使用的请求
  112. let ajaxExchangeMap = {
  113. getMarketList: Market.getMarketList,
  114. getBooks: Market.getBooks,
  115. sell: "sellList_",
  116. sellList: "sellList",
  117. buy: "buyList_",
  118. buyList: "buyList",
  119. trade: "tradeList_",
  120. tradeList: "tradeList",
  121. market: "exchangeMarketList",
  122. getSymbol(name) {
  123. return name;
  124. },
  125. };
  126. let contractExchangeMap = {
  127. getMarketList: Contract.getMarketList,
  128. getBooks: Contract.getMarketInfo,
  129. sell: "swapSellList_",
  130. sellList: "swapSellList",
  131. buy: "swapBuyList_",
  132. buyList: "swapBuyList",
  133. trade: "swapTradeList_",
  134. tradeList: "swapTradeList",
  135. market: "swapMarketList",
  136. getSymbol(name) {
  137. return name;
  138. },
  139. };
  140. export default {
  141. components: {
  142. sale,
  143. miaoRecord,
  144. symbolList,
  145. latestTransaction,
  146. coinInfo,
  147. buyOptionForm
  148. },
  149. data() {
  150. return {
  151. timeFilter: false,
  152. indexFilter: false,
  153. symbolListShow: false,
  154. active: 0,
  155. buyList: [],
  156. sellList: [],
  157. tradeList: [],
  158. activeTime: "1",
  159. index: "",
  160. marketList: [],
  161. collect: [],
  162. unSymbol: "",
  163. query: {},
  164. isLoad: false,
  165. isShow: true,
  166. price_cny: 0,
  167. app,
  168. clientHeigth: "",
  169. buyOptShow: false,
  170. buyType: 1,
  171. buyQuery:{}
  172. };
  173. },
  174. watch: {
  175. timeFilter(n) {
  176. if (n) this.indexFilter = false;
  177. },
  178. indexFilter(n) {
  179. if (n) this.timeFilter = false;
  180. },
  181. },
  182. computed: {
  183. resolutions() {
  184. let arr = [{
  185. label: "1 " + this.$t("exchange.e10"),
  186. value: "1",
  187. },
  188. {
  189. label: "5 " + this.$t("exchange.e8"),
  190. value: "5",
  191. },
  192. {
  193. label: "15 " + this.$t("exchange.e8"),
  194. value: "15",
  195. },
  196. {
  197. label: "30 " + this.$t("exchange.e8"),
  198. value: "30",
  199. },
  200. {
  201. label: "1 " + this.$t("exchange.e9"),
  202. value: "60",
  203. },
  204. {
  205. label: "1 " + this.$t("exchange.f0"),
  206. value: "1D",
  207. },
  208. {
  209. label: "1 " + this.$t("exchange.f1"),
  210. value: "1W",
  211. },
  212. {
  213. label: "1 " + this.$t("exchange.f2"),
  214. value: "1M",
  215. },
  216. ];
  217. return arr;
  218. },
  219. activeTimeObj() {
  220. return this.resolutions.find((item) => item.value == this.activeTime);
  221. },
  222. isLogin() {
  223. return Boolean(uni.getStorageSync("token"));
  224. },
  225. // 当前选中的coin
  226. activeCoin() {
  227. if (!this.marketList.length) return {};
  228. let list = [];
  229. this.marketList.forEach((parentItem) => {
  230. parentItem.marketInfoList.forEach((item) => {
  231. list.push(item);
  232. });
  233. });
  234. return list.find((item) => item.pair_name == this.query.code);
  235. },
  236. // 是否为自选
  237. isCoolect() {
  238. return this.collect
  239. .map((item) => item.pair_name)
  240. .includes(this.query.code);
  241. },
  242. ...mapState({
  243. socket: "ws",
  244. socket1: "ws1",
  245. theme: "theme",
  246. }),
  247. ajax() {
  248. return this.query.contract ? contractExchangeMap : ajaxExchangeMap;
  249. },
  250. ws() {
  251. return this.query.contract ? this.socket1 : this.socket;
  252. },
  253. iframeQuery() {
  254. if (this.query.contract) {
  255. return {
  256. getLinkUrl: this.app.baseUrl + "/api/app/contract/getKline",
  257. symbol: this.query.code.split("/")[0],
  258. theme: this.theme,
  259. ws: this.app.socketUrl1,
  260. interval: this.activeTime,
  261. resolutions: this.resolutions.map((item) => item.value),
  262. contract: 1,
  263. };
  264. } else {
  265. return {
  266. getLinkUrl: this.app.baseUrl + "/api/app/option/getKline",
  267. symbol: this.query.code,
  268. theme: this.theme,
  269. ws: this.app.socketUrl,
  270. interval: this.activeTime,
  271. resolutions: this.resolutions.map((item) => item.value),
  272. };
  273. }
  274. },
  275. mobileBase() {
  276. // #ifdef APP-PLUS
  277. if (plus.os.name == "Android") {
  278. return "";
  279. //return this.app.mobile+'/';
  280. } else {
  281. return this.app.mobile + "/";
  282. }
  283. // #endif
  284. // #ifdef H5
  285. return "/";
  286. // #endif
  287. },
  288. },
  289. methods: {
  290. setQuery: qs.stringify,
  291. omitTo: math.omitTo,
  292. resetWaiting() {
  293. },
  294. // 刷新购买记录
  295. refreshRecord(){
  296. this.$refs.miaoRecord.getList()
  297. },
  298. // 页面通知图形
  299. tabInterval(idx) {
  300. // if (this.isLoad) return;
  301. // this.isLoad = true;
  302. this.activeTime = idx;
  303. },
  304. // 图形通知页面
  305. changeInterval($ev) {
  306. this.activeTime = $ev;
  307. setTimeout(() => {
  308. this.isLoad = false;
  309. }, 300);
  310. },
  311. getBooks() {
  312. this.ajax
  313. .getBooks({
  314. symbol: this.ajax.getSymbol(this.query.code),
  315. })
  316. .then((res) => {
  317. this.buyList = res.data[this.ajax.buyList];
  318. this.sellList = res.data[this.ajax.sellList];
  319. this.tradeList = res.data[this.ajax.tradeList];
  320. });
  321. },
  322. // 获取市场行情
  323. getMarketList() {
  324. this.ajax.getMarketList().then((res) => {
  325. this.marketList = res.data;
  326. this.linkSocket(this.activeCoin.symbol);
  327. this.symbolListSocket();
  328. });
  329. },
  330. // 获取自选列表
  331. getCollect() {
  332. if (!this.isLogin) return;
  333. Home.getCollect()
  334. .then((res) => {
  335. this.collect = res.data || [];
  336. })
  337. .catch(() => {});
  338. },
  339. // 切换币种
  340. checkSymbol(obj) {
  341. this.symbolListShow = false;
  342. if (obj.pair_name == this.query.code) return;
  343. // this.query = {code:obj.pair_name};
  344. this._router.replace({
  345. path: "/pages/exchange/index",
  346. query: {
  347. code: obj.pair_name,
  348. contract: this.query.contract
  349. },
  350. });
  351. // this._router.replace({
  352. // path: "/pages/exchange/contract-miao-detail",
  353. // query: {
  354. // code: obj.pair_name
  355. // },
  356. // });
  357. this.getBooks();
  358. },
  359. // 添加自选
  360. option() {
  361. let data = {
  362. pair_name: this.query.code,
  363. };
  364. Home.option(data)
  365. .then((res) => {
  366. this.getCollect();
  367. if (res.data) {
  368. this.$toast(this.$t("exchange.a6"));
  369. } else {
  370. this.$toast(this.$t("exchange.a7"));
  371. }
  372. })
  373. .catch(() => {});
  374. },
  375. // 获取汇率
  376. getCurrencyExCny() {
  377. Exchange.getCurrencyExCny({
  378. coin_name: this.query.code.split("/")[1],
  379. }).then((res) => {
  380. this.price_cny = res.data.price_cny;
  381. });
  382. },
  383. // 链接socket
  384. linkSocket(symbol) {
  385. this.unSymbol = symbol;
  386. // 订阅买线
  387. this.ws.send({
  388. cmd: "sub",
  389. msg: `${this.ajax.buy}${symbol}`,
  390. });
  391. // 订阅卖线
  392. this.ws.send({
  393. cmd: "sub",
  394. msg: `${this.ajax.sell}${symbol}`,
  395. });
  396. // 订阅成交
  397. this.ws.send({
  398. cmd: "sub",
  399. msg: `${this.ajax.trade}${symbol}`,
  400. });
  401. },
  402. // 取消订阅
  403. unLink(symbol) {
  404. // 取消买线
  405. this.ws.send({
  406. cmd: "unsub",
  407. msg: `${this.ajax.buy}${symbol}`,
  408. });
  409. // 取消卖线
  410. this.ws.send({
  411. cmd: "unsub",
  412. msg: `${this.ajax.sell}${symbol}`,
  413. });
  414. // 取消成交
  415. this.ws.send({
  416. cmd: "unsub",
  417. msg: `${this.ajax.trade}${symbol}`,
  418. });
  419. },
  420. // 左侧的socket 不做切换要单独开来
  421. symbolListSocket() {
  422. this.ws.send({
  423. cmd: "sub",
  424. msg: this.ajax.market,
  425. });
  426. },
  427. // 接受socket
  428. socketMessage() {
  429. this.ws.on("message", (res) => {
  430. if (!this.isShow) return;
  431. let {
  432. data,
  433. sub
  434. } = res;
  435. let symbol = this.query.code.replace("/", "").toLocaleLowerCase();
  436. if (sub == this.ajax.market) {
  437. this.marketList = data;
  438. }
  439. if (sub == `${this.ajax.buy}${symbol}`) {
  440. this.buyList = data;
  441. }
  442. if (sub == `${this.ajax.sell}${symbol}`) {
  443. this.sellList = data;
  444. }
  445. if (sub == `${this.ajax.trade}${symbol}`) {
  446. this.tradeList.unshift(data);
  447. this.tradeList.pop();
  448. }
  449. });
  450. },
  451. getHeightScreen() {
  452. //改动的mmmm
  453. // #ifdef H5
  454. var oMeta = document.createElement("meta");
  455. oMeta.content = "yes";
  456. oMeta.name = "apple-mobile-web-app-capable";
  457. document.getElementsByTagName("head")[0].appendChild(oMeta);
  458. // #endif
  459. let clientHieght = document.documentElement.clientHeight;
  460. console.log(clientHieght);
  461. let mainHeight = clientHieght - 100;
  462. this.clientHeigth = 'max-height:' + mainHeight + 'px';
  463. },
  464. buyShow(idx) {
  465. this.buyType = idx;
  466. this.buyQuery = {
  467. pair_time_name:this.query.code
  468. }
  469. this.buyOptShow = true;
  470. },
  471. back() {
  472. uni.navigateBack()
  473. }
  474. },
  475. onUnload() {
  476. this.isShow = false;
  477. this.unLink(this.unSymbol);
  478. },
  479. onLoad(query) {
  480. this.getHeightScreen();
  481. this.query = query;
  482. this.isShow = true;
  483. this.getBooks();
  484. this.getMarketList();
  485. this.getCollect();
  486. this.socketMessage();
  487. // this.getCurrencyExCny();
  488. },
  489. destroyed() {
  490. this.ws.send({
  491. cmd: "unsub",
  492. msg: this.ajax.market,
  493. });
  494. this.unLink(this.unSymbol);
  495. },
  496. };
  497. </script>
  498. <style lang="scss" scoped>
  499. .price-data {
  500. position: relative;
  501. .filter {
  502. label {
  503. .button {
  504. border: none;
  505. background: none;
  506. &:active {
  507. color: $theme-1;
  508. }
  509. }
  510. input {
  511. display: none;
  512. }
  513. .filter-panel {
  514. position: absolute;
  515. top: 103%;
  516. left: $padding-md;
  517. right: $padding-md;
  518. overflow: hidden;
  519. button {
  520. background: none;
  521. border: none;
  522. &.active,
  523. &:active {
  524. color: $theme-1;
  525. }
  526. }
  527. }
  528. }
  529. }
  530. }
  531. .chart-tradingview {
  532. height: 450px;
  533. width: 100%;
  534. }
  535. .footer {
  536. box-shadow: var(--tab-nav-shadow, 0 -7px 20px 0 rgba(37, 37, 48, 0.83));
  537. position: fixed;
  538. bottom: 0;
  539. width: 100%;
  540. z-index: 2;
  541. background: var(--ronqi);
  542. }
  543. .pjwidth {
  544. width: 250upx !important;
  545. overflow: hidden;
  546. }
  547. .buyBtn {
  548. background: linear-gradient(328deg, #07c087 0%, #07c087 100%);
  549. }
  550. .sellBtn {
  551. background: linear-gradient(135deg, #ff7c6e 0%, #f7427b 100%);
  552. }
  553. .jybtn {
  554. width: 300upx;
  555. color: var(--dd);
  556. border-radius: 60upx;
  557. padding: 20upx;
  558. text-align: center;
  559. display: inline-block;
  560. margin-right: 10upx;
  561. }
  562. </style>