custom.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div class="custom">
  3. <i class="icon icon-custom" @click="toggleShow"></i>
  4. <main class="custom-main" v-if="show">
  5. <ul class="custom-list">
  6. <li class="custom-list-item">
  7. <label>data</label>
  8. <input type="text" v-model="custom.data">
  9. </li>
  10. <li class="custom-list-item">
  11. <label>description</label>
  12. <input type="text" v-model="custom.description">
  13. </li>
  14. <li class="custom-list-item">
  15. <label>extension</label>
  16. <input type="text" v-model="custom.extension">
  17. </li>
  18. </ul>
  19. <ul class="custom-footer">
  20. <button class="btn btn-cancel" @click="cancel">{{$t('取消')}}</button>
  21. <button
  22. class="btn btn-default"
  23. :disabled="!custom.data && !custom.description && custom.extension"
  24. @click="submit">{{$t('发送')}}</button>
  25. </ul>
  26. </main>
  27. <div v-if="show" class="mask" @click.self="toggleShow"></div>
  28. </div>
  29. </template>
  30. <script lang="ts">
  31. import { defineComponent, reactive, watchEffect, toRefs } from 'vue';
  32. const Custom = defineComponent({
  33. props: {
  34. show: {
  35. type: Boolean,
  36. default: () => {
  37. return false;
  38. }
  39. },
  40. },
  41. setup(props:any, ctx:any) {
  42. const data = reactive({
  43. show: false,
  44. custom: {
  45. data: '',
  46. description: '',
  47. extension: ''
  48. },
  49. TUIServer: null,
  50. });
  51. data.TUIServer = Custom.TUIServer;
  52. watchEffect(()=>{
  53. data.show = props.show;
  54. });
  55. const toggleShow = () => {
  56. data.show = !data.show;
  57. };
  58. const cancel = () => {
  59. data.custom = {
  60. data: '',
  61. description: '',
  62. extension: ''
  63. };
  64. toggleShow();
  65. };
  66. const submit = () => {
  67. Custom.TUIServer.sendCustomMessage(data.custom);
  68. cancel();
  69. };
  70. return {
  71. ...toRefs(data),
  72. toggleShow,
  73. cancel,
  74. submit,
  75. };
  76. },
  77. });
  78. export default Custom;
  79. </script>
  80. <style lang="scss" scoped>
  81. .custom {
  82. display: inline-block;
  83. position: relative;
  84. &-main {
  85. position: absolute;
  86. z-index: 5;
  87. width: 315px;
  88. background: #ffffff;
  89. top: -180px;
  90. box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
  91. padding: 10px;
  92. display: flex;
  93. flex-direction: column;
  94. }
  95. &-list {
  96. flex: 1;
  97. display: flex;
  98. flex-direction: column;
  99. &-item {
  100. padding-bottom: 15px;
  101. label {
  102. width: 88px;
  103. font-size: 18px;
  104. padding: 0 20px;
  105. display: inline-block;
  106. }
  107. input {
  108. flex: 1;
  109. height: 24px;
  110. padding: 0 10px;
  111. border: 1px solid #dddddd;
  112. border-radius: 5px;
  113. }
  114. }
  115. }
  116. &-footer {
  117. display: flex;
  118. align-items: center;
  119. justify-content: space-around;
  120. }
  121. }
  122. .btn {
  123. padding: 8px 20px;
  124. border-radius: 4px;
  125. border: none;
  126. font-weight: 400;
  127. font-size: 14px;
  128. color: #FFFFFF;
  129. letter-spacing: 0;
  130. text-align: center;
  131. line-height: 20px;
  132. &-cancel {
  133. border: 1px solid #dddddd;
  134. color: #666666;
  135. }
  136. &-default {
  137. background: #006EFF;
  138. border: 1px solid #006EFF;
  139. }
  140. &:disabled {
  141. opacity: 0.3;
  142. }
  143. }
  144. .mask {
  145. position: fixed;
  146. width: 100vw;
  147. height: 100vh;
  148. top: 0;
  149. left: 0;
  150. opacity: 0;
  151. z-index: 1;
  152. }
  153. </style>