index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="contract">
  3. <headContent :showleftRight="false">
  4. <template #content>
  5. <view class="navigation-box">
  6. <view :class="['navigation-item hide_1' , contractIndex === index ? 'active-navigation-item' : '']"
  7. v-for="(item , index) in contractArr" :key="`navigation_${index}`"
  8. @click.stop="contractIndex = index">
  9. {{ item }}
  10. </view>
  11. </view>
  12. </template>
  13. </headContent>
  14. <!-- 永续合约 -->
  15. <template v-if="contractIndex === 0">
  16. <sustainability ref="sustainabilityRef" :currency-info="currencyVal" :myTransaction="my_transaction"
  17. :pagesInfo="pagesInfo" :my-peding-transaction="my_peding_transaction" @refreshData="init"
  18. @setContract="setContract" @setProfitLoss="setProfitLoss" @setHighInfo="setHighInfo" @shareContent="val => $refs.shareRef.openShare(val)"/>
  19. </template>
  20. <!-- 永续合约 -->
  21. <template v-if="contractIndex === 1">
  22. <shortcut :myFast="my_fast" :rate-profits-total="rate_profits_total"
  23. :pagesInfo="pagesInfo" @refreshData="init" @shareContent="val => $refs.shareRef.openShare(val)"/>
  24. </template>
  25. <!-- 赠金交易 -->
  26. <template v-if="contractIndex === 2">
  27. <grants />
  28. </template>
  29. <notarize />
  30. <!-- 永续合约设置 -->
  31. <contract-set ref="contractSetRef" @confirm="openSet" />
  32. <!-- 偏好设置 -->
  33. <preference ref="preferenceRef" />
  34. <!-- 设置盈亏 -->
  35. <restrictPopup ref="restrictPopupRef" @setSuccess="setRestrictSuccess" />
  36. <!-- 分享 -->
  37. <sharePage ref="shareRef" :shareType="2"></sharePage>
  38. <!-- 平仓 -->
  39. <close-out ref="closeoutRef"></close-out>
  40. </view>
  41. </template>
  42. <script>
  43. import notarize from "./modules/notarize.vue"
  44. import sustainability from "./sustainability/index.vue"
  45. import grants from "./grants/index.vue"
  46. import shortcut from "./shortcut/index.vue"
  47. import preference from "@/components/contract-set/preference.vue"
  48. import {
  49. Api_getLeverDeal,
  50. Api_getRegister
  51. } from "@/api/index.js"
  52. import {
  53. Way_getUserInfo
  54. } from "@/utils/common-request.js"
  55. import {
  56. mapGetters
  57. } from 'vuex'
  58. import {
  59. startSocket,
  60. closeSocket
  61. } from "@/utils/websocket.js"
  62. import restrictPopup from "./modules/restrict.vue"
  63. import closeOut from "./modules/close-out.vue"
  64. import {
  65. getCurrencyMarket
  66. } from "@/utils/currency-market.js"
  67. export default {
  68. name: 'contract',
  69. components: {
  70. notarize,
  71. sustainability,
  72. grants,
  73. shortcut,
  74. preference,
  75. restrictPopup,
  76. closeOut
  77. },
  78. data() {
  79. return {
  80. contractIndex: 0,
  81. contractArr: [
  82. '永续合约',
  83. '快捷合约',
  84. '赠金交易'
  85. ],
  86. currency: {},
  87. UserInfo: {},
  88. pagesInfo: {},
  89. my_transaction: [], // 永续 当前持仓
  90. my_peding_transaction:[], // 永续 限价持仓
  91. my_fast:[],// 快捷合约 持仓
  92. rate_profits_total: {}
  93. };
  94. },
  95. onLoad() {
  96. },
  97. computed: {
  98. ...mapGetters([
  99. 'currencyVal'
  100. ]),
  101. },
  102. watch: {
  103. currencyVal: {
  104. handler(newCurrency) {
  105. if (newCurrency && newCurrency?.legal_id) {
  106. this.init();
  107. }
  108. },
  109. deep: true,
  110. immediate: true
  111. },
  112. },
  113. onShow() {
  114. const nu = this.$getStorageSync('contractIndex');
  115. this.contractIndex = [0, 1, 2].includes(nu) ? nu : this.contractIndex
  116. this.$removeStorageSync('contractIndex')
  117. this.init()
  118. // this.setSocket();
  119. },
  120. onHide() {
  121. this.close()
  122. },
  123. mounted() {
  124. // 设置盈亏
  125. // setProfitLoss(item) {
  126. // console.log('setProfitLoss')
  127. // this.$nextTick(() => {
  128. // this.$refs.restrictPopupRef.open(item)
  129. // })
  130. // },
  131. // this.$on('setProfitLoss', (val) => {
  132. // console.log('setProfitLoss' , val);
  133. // });
  134. },
  135. methods: {
  136. close(){
  137. closeSocket() // 停止 Socket
  138. this.$store.commit('websocket/set_currencySuspend', false) // 停止币种刷新
  139. },
  140. init() {
  141. // if ([0, 1].includes(this.contractIndex)) {
  142. // // 永续 / 快捷 需要获取持仓信息
  143. // this.getRegister()
  144. // }
  145. this.getAccountInfo();
  146. getCurrencyMarket('contract', {onceRefresh:true})
  147. // this.$store.dispatch('websocket/getQuotationNew', {
  148. // noRefresh: true
  149. // })
  150. // 运行 socket 实时更新
  151. // this.$store.commit('websocket/set_socket_update_status', true)
  152. if (this.currencyVal && this.currencyVal?.legal_id) {
  153. this.getLeverDeal();
  154. this.setSocket();
  155. }
  156. },
  157. setSocket() {
  158. startSocket();
  159. },
  160. getLeverDeal() {
  161. Api_getLeverDeal({
  162. legal_id: this.currencyVal.legal_id,
  163. currency_id: this.currencyVal.currency_id
  164. }).then(res => {
  165. this.pagesInfo = res
  166. this.my_transaction = res.my_transaction || []; // 永续合约 - 持仓信息
  167. this.my_peding_transaction = res.my_peding_transaction || []; // 永续合约 - 限价委托
  168. this.my_fast = res.my_fast || []; // 快捷合约 - 持仓信息
  169. console.log('my_transaction' , this.my_transaction)
  170. }).catch(err => {
  171. // this.getLeverDeal()
  172. })
  173. },
  174. getAccountInfo() {
  175. this.$store.dispatch('possession/getPossession').then(res => {
  176. console.log('获取成功')
  177. }).catch(err => {
  178. console.log('获取shibai ')
  179. })
  180. },
  181. setContract() {
  182. // setContract
  183. this.$nextTick(() => {
  184. this.$refs.contractSetRef.open()
  185. })
  186. },
  187. // 设置盈亏
  188. setProfitLoss(item) {
  189. this.$nextTick(() => {
  190. this.$refs.restrictPopupRef.open(item)
  191. })
  192. },
  193. // 设置盈亏成功
  194. setRestrictSuccess() {
  195. this.getRegister();
  196. this.getLeverDeal();
  197. },
  198. // 永续合约 设置
  199. openSet(type) {
  200. return false
  201. switch (type) {
  202. case 1:
  203. // 偏好设置
  204. this.$nextTick(() => {
  205. this.$refs.preferenceRef.open()
  206. })
  207. break;
  208. case 2:
  209. // 合约计算器
  210. uni.navigateTo({
  211. url: '/pages/contract/calculator'
  212. })
  213. break;
  214. //
  215. }
  216. },
  217. setHighInfo(){
  218. this.$refs.restrictPopupRef.open()
  219. }
  220. }
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. .navigation-box {
  225. width: 100%;
  226. height: 100%;
  227. padding: 0 $pages-padding 11rpx;
  228. display: flex;
  229. align-items: flex-end;
  230. .navigation-item {
  231. // width: 25%;
  232. flex: 1;
  233. flex-shrink: 0;
  234. text-align: center;
  235. height: 60rpx;
  236. border: 2rpx solid #27ae83;
  237. line-height: 60rpx;
  238. font-size: 28rpx;
  239. font-family: PingFang SC, PingFang SC-Regular;
  240. font-weight: 400;
  241. color: #05c175;
  242. &:nth-child(n + 2) {
  243. border-left: none;
  244. }
  245. &:last-child {
  246. border-radius: 0 6rpx 6rpx 0;
  247. }
  248. &:first-child {
  249. border-radius: 6rpx 0 0 6rpx;
  250. }
  251. }
  252. .active-navigation-item {
  253. background-color: #05C175;
  254. color: #FFFFFF;
  255. }
  256. }
  257. </style>