index.vue 5.6 KB

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