index.vue 6.4 KB

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