editDialog.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <view>
  3. <view
  4. class="editMask"
  5. v-if="isShow"
  6. :style="{
  7. height: height + 'px',
  8. }"
  9. @click.stop
  10. >
  11. <view
  12. class="editDialog"
  13. @click.stop
  14. >
  15. <view>
  16. <text class="title">{{ title }}</text>
  17. </view>
  18. <textarea
  19. v-model="value"
  20. type="text"
  21. placeholder="请输入..."
  22. class="textarea"
  23. />
  24. <view class="btnGroup">
  25. <view
  26. class="btnItem left"
  27. @click="hide"
  28. >
  29. <text class="btnText">取消</text>
  30. </view>
  31. <view
  32. class="btnItem right"
  33. @click="save"
  34. >
  35. <text class="btnText">提交</text>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. let success, error;
  44. export default {
  45. data() {
  46. return {
  47. /**
  48. * 是否展示
  49. */
  50. isShow: false,
  51. /**
  52. * 标题
  53. */
  54. title: "",
  55. /**
  56. * 输入框的值
  57. */
  58. value: "",
  59. /**
  60. * 屏幕高度
  61. */
  62. height: uni.getSystemInfoSync().windowHeight,
  63. };
  64. },
  65. mounted() {
  66. let that = this;
  67. /**
  68. * 使用uni.$on打开弹窗
  69. */
  70. uni.$on("devTools_showEditDialog", (options) => {
  71. that
  72. .show(options.title, options.value)
  73. .then((val) => {
  74. uni.$emit("devTools_editDialogSaveSuccess", val);
  75. })
  76. .catch(() => {
  77. uni.$emit("devTools_editDialogClose");
  78. });
  79. });
  80. },
  81. beforeDestroy() {
  82. uni.$off("devTools_showEditDialog");
  83. },
  84. methods: {
  85. /**
  86. * 展示弹窗
  87. */
  88. show(title = "标题", value = "") {
  89. let that = this;
  90. return new Promise((yes, err) => {
  91. success = yes;
  92. error = err;
  93. that.title = title;
  94. that.value = value ? value : "";
  95. that.isShow = true;
  96. });
  97. },
  98. /**
  99. * 关闭弹窗
  100. */
  101. hide() {
  102. this.isShow = false;
  103. error();
  104. },
  105. /**
  106. * 保存
  107. */
  108. save() {
  109. this.isShow = false;
  110. success(this.value);
  111. },
  112. },
  113. };
  114. </script>
  115. <style lang="scss" scoped>
  116. .editMask {
  117. display: flex;
  118. flex-direction: column;
  119. align-items: center;
  120. justify-content: center;
  121. background-color: rgba(0, 0, 0, 0.3);
  122. width: 750rpx;
  123. flex: 1;
  124. /* #ifndef APP-PLUS */
  125. height: 100vh;
  126. backdrop-filter: blur(1px);
  127. /* #endif */
  128. position: fixed;
  129. left: 0;
  130. top: 0;
  131. z-index: 999;
  132. .editDialog {
  133. display: flex;
  134. flex-direction: column;
  135. align-items: center;
  136. justify-content: center;
  137. width: 690rpx;
  138. background-color: #fff;
  139. border-radius: 20rpx;
  140. padding: 20rpx;
  141. .title {
  142. font-size: 28rpx;
  143. line-height: 28rpx;
  144. color: #333;
  145. /* #ifndef APP-PLUS */
  146. max-width: 600rpx;
  147. word-wrap: break-word;
  148. /* #endif */
  149. /* #ifdef APP-PLUS */
  150. width: 600rpx;
  151. /* #endif */
  152. }
  153. .textarea {
  154. margin-top: 20rpx;
  155. margin-bottom: 20rpx;
  156. width: 640rpx;
  157. /* #ifndef APP-PLUS */
  158. min-height: 200rpx;
  159. max-height: 750rpx;
  160. /* #endif */
  161. background-color: rgba(0, 0, 0, 0.02);
  162. padding: 10rpx;
  163. }
  164. .btnGroup {
  165. display: flex;
  166. flex-direction: row;
  167. width: 640rpx;
  168. justify-content: space-between;
  169. .btnItem {
  170. height: 64rpx;
  171. border-radius: 10rpx;
  172. display: flex;
  173. flex-direction: row;
  174. align-items: center;
  175. justify-content: center;
  176. .btnText {
  177. font-size: 24rpx;
  178. color: #fff;
  179. }
  180. &.left {
  181. width: 160rpx;
  182. background-color: #8799a3;
  183. }
  184. &.right {
  185. width: 450rpx;
  186. background-color: #3cbb45;
  187. }
  188. }
  189. }
  190. }
  191. }
  192. </style>