OrderTimeSheet.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <Teleport to="body">
  3. <transition name="fade">
  4. <div v-if="visible" class="modal-mask" @click="closeModal"></div>
  5. </transition>
  6. <transition name="slide-up">
  7. <div v-if="visible" class="modal-panel">
  8. <div class="panel-handle-wrap">
  9. <div class="panel-handle"></div>
  10. </div>
  11. <div class="panel-title">订单时效</div>
  12. <div class="option-list">
  13. <div
  14. v-for="item in options"
  15. :key="item.value"
  16. class="option-item"
  17. @click="selectOption(item.value)"
  18. >
  19. <span :class="{ 'active-text': modelValue === item.value }">
  20. {{ item.label }}
  21. </span>
  22. <div v-if="modelValue === item.value" class="check-icon">
  23. <svg viewBox="0 0 1024 1024" width="16" height="16">
  24. <path d="M512 0C229.23 0 0 229.23 0 512s229.23 512 512 512 512-229.23 512-512S794.77 0 512 0z" fill="#E03C3C"/>
  25. <path d="M426.67 725.33L213.33 512l60.33-60.33L426.67 604.67 750.33 281l60.34 60.33-384 384z" fill="#FFFFFF"/>
  26. </svg>
  27. </div>
  28. </div>
  29. </div>
  30. <div class="safe-area-bottom"></div>
  31. </div>
  32. </transition>
  33. </Teleport>
  34. </template>
  35. <script setup>
  36. import { defineProps, defineEmits } from 'vue';
  37. import { toRef } from 'vue' // 1. 引入 toRef
  38. import { useBodyScrollLock } from '@/composables/useBodyScrollLock' // 2. 引入 Hook
  39. // 定义接收的属性
  40. const props = defineProps({
  41. visible: {
  42. type: Boolean,
  43. default: false
  44. },
  45. modelValue: {
  46. type: String,
  47. default: ''
  48. }
  49. });
  50. useBodyScrollLock(toRef(props, 'visible'))
  51. // 定义抛出的事件
  52. const emit = defineEmits(['update:visible', 'update:modelValue']);
  53. // 选项数据 (模拟设计稿内容)
  54. const options = [
  55. { label: 'GTC(一直有效直到取消)', value: 'GTC' },
  56. { label: 'IOC(立即成交否则取消)', value: 'IOC' },
  57. { label: 'FOK(全部成交否则取消)', value: 'FOK' }
  58. ];
  59. // 选择逻辑
  60. const selectOption = (value) => {
  61. emit('update:modelValue', value); // 带回选中的值
  62. closeModal(); // 关闭弹窗
  63. };
  64. // 关闭逻辑
  65. const closeModal = () => {
  66. emit('update:visible', false);
  67. };
  68. </script>
  69. <style scoped>
  70. /* 遮罩层样式 */
  71. .modal-mask {
  72. position: fixed;
  73. top: 0;
  74. left: 0;
  75. width: 100vw;
  76. height: 100vh;
  77. background-color: rgba(0, 0, 0, 0.5);
  78. z-index: 1000;
  79. }
  80. /* 弹窗主体样式 */
  81. .modal-panel {
  82. position: fixed;
  83. bottom: 0;
  84. left: 0;
  85. width: 100%;
  86. background: white;
  87. border-radius: 16px 16px 0 0;
  88. padding: 10px 0 0 0;
  89. z-index: 1001;
  90. box-sizing: border-box;
  91. /* 模拟手机最大宽度,防止在PC上太宽 */
  92. max-width: 600px;
  93. left: 50%;
  94. transform: translateX(-50%);
  95. }
  96. /* 顶部小灰条 */
  97. .panel-handle-wrap {
  98. display: flex;
  99. justify-content: center;
  100. padding-bottom: 20px;
  101. }
  102. .panel-handle {
  103. width: 36px;
  104. height: 4px;
  105. background: #E0E0E0;
  106. border-radius: 2px;
  107. }
  108. /* 标题 */
  109. .panel-title {
  110. font-size: 18px;
  111. font-weight: bold;
  112. color: #333;
  113. padding: 0 20px 20px 20px;
  114. }
  115. /* 列表项 */
  116. .option-list {
  117. padding: 0 20px;
  118. }
  119. .option-item {
  120. display: flex;
  121. justify-content: space-between;
  122. align-items: center;
  123. padding: 16px 0;
  124. font-size: 16px;
  125. color: #999; /* 未选中默认为灰色 */
  126. cursor: pointer;
  127. }
  128. /* 选中时的文字颜色 */
  129. .active-text {
  130. color: #333;
  131. font-weight: 500;
  132. }
  133. .check-icon {
  134. display: flex;
  135. align-items: center;
  136. }
  137. .safe-area-bottom {
  138. height: 30px; /* 简单的安全区预留 */
  139. }
  140. /* Vue 动画过渡类 */
  141. .fade-enter-active, .fade-leave-active {
  142. transition: opacity 0.3s ease;
  143. }
  144. .fade-enter-from, .fade-leave-to {
  145. opacity: 0;
  146. }
  147. .slide-up-enter-active, .slide-up-leave-active {
  148. transition: transform 0.3s ease;
  149. }
  150. .slide-up-enter-from, .slide-up-leave-to {
  151. transform: translate(-50%, 100%); /* 从底部滑出 */
  152. }
  153. </style>