投屏pc端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

247 lines
6.9 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. <template>
  2. <div class="ce-warp">
  3. <div class="ce-warp1 ex-content-top">
  4. <!-- 左侧部分 -->
  5. <div class="ce-div1 hc-bgColor1" v-if="sideShow">
  6. <div class="list-div1 hc-bgColor3">
  7. <div class="list-div1-div1">
  8. <h2>{{$t('净资产折合')}}:</h2>
  9. <p>
  10. {{tradeCoinBalance}} {{currentPair.dealCoin}}
  11. <span class="hc-color hc-colors">0 CNY</span>
  12. </p>
  13. <div class="hide">
  14. <i class="fa-eye"></i>
  15. </div>
  16. </div>
  17. </div>
  18. <release-pair @updateOrder="updateOrder"></release-pair>
  19. </div>
  20. <!-- 中间部分 -->
  21. <div class="ce-div2 hc-bgColor1" :class="{'active': !sideShow}">
  22. <release-update @sideToggle="sideToggle"></release-update>
  23. <div class="qushi-box">
  24. <!-- K线 -->
  25. <div class="trade-chart-box" style="width: 100%;height: 100%;"><component ref="tradingViewChart" v-bind:is="tradingviewContainer" /></div>
  26. </div>
  27. <!-- 交易表单 -->
  28. <release-form :mainCoinBalance="mainCoinBalance" :tradeCoinBalance="tradeCoinBalance" @updateOrder="updateOrder"></release-form>
  29. </div>
  30. <div class="ce-div3 hc-bgColor1">
  31. <!-- 盘口数据 -->
  32. <release-depth :depthValue="depthValue" @chooseDepth="chooseDepth"></release-depth>
  33. </div>
  34. <div class="ce-div4 hc-bgColor1">
  35. <!-- 成交数据 -->
  36. <release-deal></release-deal>
  37. </div>
  38. </div>
  39. <div class="ce-warp1">
  40. <!-- 委托订单 -->
  41. <release-order ref="order"></release-order>
  42. </div>
  43. <div class="clear"></div>
  44. </div>
  45. </template>
  46. <script>
  47. import { mapState } from 'vuex'
  48. import '@/charting_library/loading.css'; //loading样式加载图
  49. import tradingView from '@/components/tv.vue'; //K线模块
  50. import tv_setting from '@/store/tv_option.js'; //K线vuex
  51. import releasePair from './components/release_pair_list'
  52. import releaseUpdate from './components/release_data_update'
  53. import releaseForm from './components/release_form'
  54. import releaseDepth from './components/release_depth'
  55. import releaseDeal from './components/release_deal'
  56. import releaseOrder from './components/release_order_list'
  57. export default {
  58. name: 'releaseTrade',
  59. components: {
  60. releasePair, //交易对列表
  61. releaseUpdate, //最新交易对数据
  62. releaseForm, //交易表单
  63. releaseDepth, //交易盘口
  64. releaseDeal, //交易成交数据
  65. releaseOrder, //委托订单
  66. },
  67. data() {
  68. return {
  69. /*---------- K线图相关 -----------*/
  70. tradingviewContainer: '',
  71. skin: this.getsetting().skin,
  72. /*---------- 自定义 -----------*/
  73. symbolId:'',//uniapp传来的交易对(小写)
  74. symbolIdLine:'UBSC-USDT',//当前交易对(大写)(xxx-xxx格式)
  75. token: '', //uniapp传来的token
  76. sub: null, //当前交易对信息
  77. depth: { sellList: [], buyList: [] }, //当前交易对信息
  78. sideShow: true, //展开币种列表
  79. mainCoinBalance: '0', //主币余额
  80. tradeCoinBalance: '0', //交易币余额
  81. depthValue: 0,
  82. timers: '', //定时器
  83. }
  84. },
  85. computed: {
  86. ...mapState('trend', ['allPairList', 'currentPair']),
  87. },
  88. watch:{
  89. currentPair(val,old){
  90. if(val.symbolId!==old.symbolId) this.restart()
  91. }
  92. },
  93. methods: {
  94. /* ---------------- 以下是K线图配置 --------------------*/
  95. //K线vuex数据
  96. getsetting() {
  97. if (!this.$store.state.tv_set) {
  98. this.$store.state.tv_setting = tv_setting;
  99. }
  100. return this.$store.state.tv_setting;
  101. },
  102. //重启K线图
  103. restart() {
  104. this.$store.state.tv_setting.symbol = this.currentPair.symbolId; //K线版块(交易对)
  105. this.$refs.tradingViewChart.symbolTab();
  106. },
  107. //初始化K线图
  108. KlinFunc() {
  109. if (!this.getsetting().wsurl) {
  110. this.$store.state.tv_setting.skin = 'white'; //K线颜色 white \ black
  111. this.$store.state.tv_setting.symbol = this.currentPair.symbolId; //K线版块(交易对)
  112. this.load();
  113. console.log(11111111)
  114. this.$store.state.tv_setting.wsurl = 'ws://119.23.49.169:10803/ws/coin/exchange';
  115. this.$store.state.tv_setting.wsCompression = 0;
  116. this.tradingviewContainer = tradingView;
  117. } else {
  118. this.tradingviewContainer = tradingView;
  119. }
  120. },
  121. setloadingstyle(tv_option) {
  122. let loading_screen = tv_option.loading_screen(this.skin);
  123. let bodyd = document.getElementById('tradingView');
  124. if (loading_screen.backgroundColor) {
  125. bodyd.style.background = loading_screen.backgroundColor;
  126. }
  127. },
  128. load() {
  129. if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent) || this.$route.name == 'mobile') {
  130. //手机端
  131. let _option = () => import('@/store/tv_option_mobile.js');
  132. _option().then(res => {
  133. this.$store.state.tv_option = res.default;
  134. //this.componentsContainer = tv;
  135. this.setloadingstyle(res.default);
  136. });
  137. } else {
  138. let _option = () => import('@/store/tv_option_pc.js');
  139. _option().then(res => {
  140. this.$store.state.tv_option = res.default;
  141. //this.componentsContainer = tv;
  142. this.setloadingstyle(res.default);
  143. });
  144. }
  145. },
  146. initCoin() { //获取初始币种
  147. this.getAxios('/api/coin/case/all')
  148. .then(data => {
  149. let list = data.data;
  150. let coin;
  151. if(this.$route.query.id) { //从其他页面,路由跳转过来
  152. list.forEach(item => {
  153. item.childen.forEach(item2 => {
  154. item2.prices.forEach(item3 => {
  155. if(item3.dealCoin == this.$route.query.id) {
  156. coin = item3;
  157. }
  158. })
  159. })
  160. });
  161. } else {
  162. list.forEach(item => {
  163. if(item.caseCode == 3) {
  164. coin = item.childen[0].prices[0];
  165. }
  166. })
  167. }
  168. this.$store.dispatch('trend/getNewPair', coin);
  169. this.getBalance();
  170. })
  171. },
  172. getBalance() { //获取余额
  173. this.getAxios('/api/user/assets/list?type=COIN_TO_COIN')
  174. .then(data => {
  175. let list = data.data;
  176. list.forEach(item => {
  177. if (item.coinId == this.currentPair.convertType) {
  178. this.mainCoinBalance = item.normalAmount;
  179. }
  180. if (item.coinId == this.currentPair.dealCoin) {
  181. this.tradeCoinBalance = item.normalAmount;
  182. }
  183. })
  184. })
  185. },
  186. sideToggle(val) { //左侧币种列表展开/收起
  187. this.sideShow = val;
  188. },
  189. getDepth() { //获取深度
  190. this.$store.dispatch('trend/getDepth', {
  191. symbol: this.currentPair.symbolId,
  192. depth: this.depthValue
  193. });
  194. },
  195. chooseDepth(val) { //切换深度
  196. this.depthValue = val;
  197. },
  198. updateOrder() { //更新订单
  199. this.$refs.order.getOrderList(1);
  200. this.getBalance();
  201. },
  202. },
  203. beforeDestroy() {
  204. clearInterval(this.timers);
  205. },
  206. created() {
  207. this.initCoin();
  208. this.KlinFunc()
  209. this.timers = setInterval(() => {
  210. this.$store.dispatch('trend/getAllPair');
  211. this.$store.dispatch('trend/getTransactions');
  212. this.$emit('updateOrder');
  213. this.getDepth();
  214. }, 1000);
  215. }
  216. }
  217. </script>
  218. <style scoped>
  219. .clear {
  220. width: 100%;
  221. height: 10px;
  222. background: #f9f9f9;
  223. overflow: hidden;
  224. clear: both;
  225. }
  226. </style>