richTextModal.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <!-- 底部弹窗样式 -->
  3. <view class="bottom_modal_mask" @click="handle('cancel')" v-if="modalData.styleType == 'bottom' && nodes.length > 0">
  4. <view class="bottom_modal" @click.stop="doNothing">
  5. <image class="bottom_modal_img" :src="iconUrl.cha" @click="handle('cancel')" v-if="modalData.showCancelBtn || false"></image>
  6. <view class="bottom_modal_tit" v-if="modalData.title">
  7. {{ modalData.title || "" }}
  8. </view>
  9. <view class="bottom_modal_con" :style="{ textAlign: modalData.contentAlign || 'justify' }">
  10. <rich-text :nodes="nodes" space="nbsp"></rich-text>
  11. </view>
  12. <view class="bottom_modal_btn_list">
  13. <view class="bottom_modal_btn_item cancelColor" :style="{ color: modalData.cancelColor || '#999' }" @click="handle('cancel')" v-if="modalData.showCancel">
  14. {{ modalData.cancelText || "取消" }}
  15. </view>
  16. <view class="bottom_modal_btn_item" @click="handle('confirm')" :style="{ color: modalData.confirmColor || 'var(--dominantColor)' }">
  17. {{ modalData.confirmText || "确定" }}
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- 居中弹窗样式 -->
  23. <view class="modal_mask" @click="handle('cancel')" v-if="modalData.styleType != 'bottom' && nodes.length > 0">
  24. <view class="modal" @click.stop="doNothing">
  25. <image class="modal_img" :src="iconUrl.cha" @click="handle('cancel')" v-if="modalData.showCancelBtn || false"></image>
  26. <view class="modal_tit" v-if="modalData.title">
  27. {{ modalData.title || "" }}
  28. </view>
  29. <view class="modal_con" :style="{ textAlign: modalData.contentAlign || 'justify' }">
  30. <rich-text :nodes="nodes" space="nbsp"></rich-text>
  31. </view>
  32. <view class="modal_btn_list">
  33. <view class="modal_btn_item cancelColor" :style="{ color: modalData.cancelColor || '#999' }" @click="handle('cancel')" v-if="modalData.showCancel">
  34. {{ modalData.cancelText || "取消" }}
  35. </view>
  36. <view class="modal_btn_item" @click="handle('confirm')" :style="{ color: modalData.confirmColor || 'var(--dominantColor)' }">
  37. {{ modalData.confirmText || "确定" }}
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script setup lang="ts">
  44. import { ref, onMounted } from 'vue';
  45. import { common } from '@/utils';
  46. import icon from '@/utils/icon';
  47. import { ArticleDetail } from '@/pagesAdmin/article/service/article';
  48. const props = withDefaults(defineProps<{
  49. modalData: {
  50. showModal?: boolean;
  51. title?: string;
  52. content?: string;
  53. node?: string; // 兼容旧逻辑
  54. contentAlign?: string;
  55. styleType?: string;
  56. articleId?: string;
  57. showCancel?: boolean;
  58. cancelText?: string;
  59. cancelColor?: string;
  60. confirmColor?: string;
  61. confirmText?: string;
  62. showCancelBtn?: boolean;
  63. }
  64. }>(), {
  65. modalData: () => ({})
  66. });
  67. const emit = defineEmits(['cancel', 'confirm', 'noData']);
  68. const nodes = ref('');
  69. const iconUrl = ref(icon)
  70. onMounted(async () => {
  71. let content = '';
  72. // 判断是否有传文章id 有传的是否查询传进来的文章id展示
  73. if (!props.modalData.node && props.modalData.articleId) {
  74. let queryData = {
  75. Status: 1,
  76. Id: props.modalData.articleId
  77. };
  78. try {
  79. let { resp } = await ArticleDetail(queryData);
  80. if (!common.isEmpty(resp) && resp[0].Content != "") {
  81. content = unescape(resp[0].Content);
  82. }
  83. } catch (e) {
  84. console.error(e);
  85. }
  86. } else if (props.modalData.content != '') {
  87. content = props.modalData.content || props.modalData.node || '';
  88. }
  89. if (common.isEmpty(content)) {
  90. emit('noData', {});
  91. return;
  92. }
  93. nodes.value = content;
  94. });
  95. const handle = (type: string) => {
  96. if (type == 'cancel') {
  97. emit('cancel', {});
  98. }
  99. if (type == 'confirm') {
  100. emit('confirm', {});
  101. }
  102. };
  103. const doNothing = () => {
  104. return;
  105. };
  106. </script>
  107. <style lang="scss" scoped>
  108. /* 底部弹窗样式 */
  109. .bottom_modal_mask {
  110. position: fixed;
  111. left: 0;
  112. top: 0;
  113. bottom: 0;
  114. right: 0;
  115. background-color: rgba(0, 0, 0, 0.6);
  116. z-index: 100;
  117. }
  118. .bottom_modal {
  119. width: 100%;
  120. min-height: 200upx;
  121. border-radius: 20upx 20upx 0 0;
  122. background-color: #fff;
  123. position: absolute;
  124. padding-top: 30upx;
  125. left: 0;
  126. bottom: 0;
  127. }
  128. .bottom_modal_tit {
  129. text-align: center;
  130. font-weight: 500;
  131. font-size: 34upx;
  132. overflow: hidden;
  133. }
  134. .bottom_modal_img {
  135. width: 35upx;
  136. height: 35upx;
  137. right: 20upx;
  138. top: 30upx;
  139. bottom: 0;
  140. position: absolute;
  141. }
  142. .bottom_modal_con {
  143. font-size: 30upx;
  144. margin: 30upx;
  145. line-height: 1.4em;
  146. max-height: 800upx;
  147. overflow: auto;
  148. }
  149. .bottom_modal_btn_list {
  150. display: flex;
  151. align-items: center;
  152. justify-content: center;
  153. border-top: 1px solid #eee;
  154. }
  155. .bottom_modal_btn_item {
  156. width: 100%;
  157. height: 100upx;
  158. text-align: center;
  159. line-height: 100upx;
  160. font-size: 34upx;
  161. }
  162. /* 居中弹窗样式 */
  163. .modal_mask {
  164. position: fixed;
  165. left: 0;
  166. top: 0;
  167. bottom: 0;
  168. right: 0;
  169. background-color: rgba(0, 0, 0, 0.6);
  170. display: flex;
  171. align-items: center;
  172. justify-content: center;
  173. z-index: 100;
  174. }
  175. .modal {
  176. width: 600upx;
  177. min-height: 200upx;
  178. border-radius: 20upx;
  179. background-color: #fff;
  180. position: relative;
  181. padding-top: 30upx;
  182. }
  183. .modal_tit {
  184. text-align: center;
  185. font-weight: 500;
  186. font-size: 34upx;
  187. overflow: hidden;
  188. }
  189. .modal_img {
  190. width: 35upx;
  191. height: 35upx;
  192. right: 20upx;
  193. top: 30upx;
  194. bottom: 0;
  195. position: absolute;
  196. }
  197. .modal_con {
  198. font-size: 30upx;
  199. margin: 30upx;
  200. line-height: 1.4em;
  201. max-height: 800upx;
  202. overflow: auto;
  203. }
  204. .modal_btn_list {
  205. display: flex;
  206. align-items: center;
  207. justify-content: center;
  208. border-top: 1px solid #eee;
  209. }
  210. .modal_btn_item {
  211. width: 100%;
  212. height: 100upx;
  213. text-align: center;
  214. line-height: 100upx;
  215. font-size: 34upx;
  216. }
  217. .cancelColor {
  218. border-right: 1px solid #eee;
  219. }
  220. </style>