TakeProfitsTopLoss.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <script setup>
  2. import { Checkbox as VanCheckbox } from 'vant';
  3. import { Icon as VanIcon, } from 'vant';
  4. import {defineAsyncComponent, ref} from 'vue';
  5. const TPSLSmartPopup = defineAsyncComponent(() => import('../components/TPSLSmartPopup.vue'));
  6. // 1. 状态控制
  7. const isEnabled = ref(false); // 控制复选框选中状态,
  8. const takeProfit = ref(''); // 止盈价格
  9. const stopLoss = ref(''); // 止损价格
  10. // 点击“高级”的事件
  11. const handleAdvanced = () => {
  12. console.log('点击了高级设置');
  13. };
  14. //止盈止损高级设置
  15. const showSmartTPSL = ref(false);
  16. const handleConfirm1 = (data) => {
  17. console.log('止盈止损设置:', data);
  18. };
  19. </script>
  20. <template>
  21. <div class="tpsl-container">
  22. <div class="header-row">
  23. <div class="left-trigger">
  24. <van-checkbox
  25. v-model="isEnabled"
  26. shape="square"
  27. checked-color="#DC4653"
  28. icon-size="16px"
  29. >
  30. </van-checkbox>
  31. <span class="label-text">止盈止损</span>
  32. <van-icon name="question-o" color="#999" size="16" class="help-icon" />
  33. </div>
  34. <div v-if="isEnabled" class="right-action" @click="handleAdvanced">
  35. <span class="fc333333" @click="showSmartTPSL = true">高级</span>
  36. <van-icon style="font-weight: bold; margin-left: 5px;" name="arrow" size="12"/>
  37. </div>
  38. </div>
  39. <transition style="min-width:205px" name="slide-fade">
  40. <div v-if="isEnabled" class="inputs-wrapper">
  41. <div class="input-box">
  42. <span class="placeholder" v-show="!takeProfit">止盈价格</span>
  43. <input
  44. type="number"
  45. v-model="takeProfit"
  46. class="real-input"
  47. />
  48. <span class="suffix">USDT</span>
  49. </div>
  50. <div class="input-box">
  51. <span class="placeholder" v-show="!stopLoss">止损价格</span>
  52. <input
  53. type="number"
  54. v-model="stopLoss"
  55. class="real-input"
  56. />
  57. <span class="suffix">USDT</span>
  58. </div>
  59. </div>
  60. </transition>
  61. <TPSLSmartPopup
  62. v-model:visible="showSmartTPSL"
  63. @confirm="handleConfirm1"
  64. ></TPSLSmartPopup>
  65. </div>
  66. </template>
  67. <style scoped>
  68. /* 容器基础样式,基于 375px 设计稿 */
  69. :deep(.van-checkbox__icon--square .van-icon) {
  70. border-radius: 2px !important;}
  71. .tpsl-container {
  72. width: 100%;
  73. background: #fff;
  74. box-sizing: border-box;
  75. }
  76. /* --- 头部样式 --- */
  77. .header-row {
  78. display: flex;
  79. justify-content: space-between;
  80. align-items: center;
  81. margin-bottom: 6px;
  82. height: 24px;
  83. }
  84. .left-trigger {
  85. display: flex;
  86. align-items: center;
  87. gap: 6px;
  88. }
  89. .label-text {
  90. font-size: 12px;
  91. color: #333;
  92. font-weight: 400;
  93. }
  94. .help-icon {
  95. margin-left: 2px;
  96. }
  97. .right-action {
  98. display: flex;
  99. align-items: center;
  100. color: #666;
  101. font-size: 12px;
  102. cursor: pointer;
  103. }
  104. /* --- 输入框区域样式 --- */
  105. .inputs-wrapper {
  106. max-width: 204.25px;
  107. display: flex;
  108. flex-direction: column;
  109. gap: 12px; /* 两个输入框之间的间距 */
  110. }
  111. .input-box {
  112. position: relative; /* 为了让 placeholder 绝对定位 */
  113. display: flex;
  114. align-items: center;
  115. background-color: #F7F8FA; /* 还原图片中的浅灰色背景 */
  116. border-radius: 4px;
  117. height: 38px;
  118. padding: 0 12px;
  119. }
  120. /* 模拟 placeholder,为了更好控制样式和位置 */
  121. .placeholder {
  122. position: absolute;
  123. left: 12px;
  124. color: #969799; /* 浅灰提示字 */
  125. font-size: 14px;
  126. pointer-events: none; /* 点击穿透,确保能点到 input */
  127. }
  128. /* 实际的输入框,背景透明覆盖在上面 */
  129. .real-input {
  130. flex: 1; /* 占满剩余空间 */
  131. background: transparent;
  132. border: none;
  133. outline: none;
  134. font-size: 14px;
  135. color: #333;
  136. z-index: 1;
  137. height: 100%;
  138. text-align: right;
  139. padding-right: 8px;
  140. }
  141. /* 让 real-input 靠左对齐输入 (还原图片样子) */
  142. .real-input {
  143. text-align: left;
  144. }
  145. .suffix {
  146. color: #333;
  147. font-size: 14px;
  148. font-weight: 400;
  149. position: absolute;
  150. right: 12px;
  151. }
  152. /* --- 简单的展开/收起动画 --- */
  153. .slide-fade-enter-active,
  154. .slide-fade-leave-active {
  155. transition: all 0.3s ease-out;
  156. max-height: 200px; /* 只要比实际高度大就行 */
  157. opacity: 1;
  158. overflow: hidden;
  159. }
  160. .slide-fade-enter-from,
  161. .slide-fade-leave-to {
  162. max-height: 0;
  163. opacity: 0;
  164. margin-top: 0;
  165. }
  166. </style>