graceEditor.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view class="grace-editor">
  3. <textarea class="grace-editor-title" v-model="article.title" placeholder="# 请输入标题" auto-height />
  4. <!-- 内容区域 -->
  5. <view v-for="(item, index) in article.contents" :key="index" class="grace-editor-items">
  6. <!-- 普通文本 -->
  7. <textarea class="grace-editor-txt" maxlength="-1" :data-index="index" v-if="item.type == 'txt'"
  8. @input="graceEditorInput" :value="item.content" placeholder="# 请在此处输入文本内容" auto-height />
  9. <!-- 居中标题 -->
  10. <input type="text" class="grace-editor-center" maxlength="-1" :data-index="index"
  11. @input="graceEditorInput" :value="item.content" placeholder="# 输入居中题目" v-else-if="item.type == 'center'" />
  12. <!-- 图片 -->
  13. <view class="grace-editor-img-wrap" v-else-if="item.type == 'img'">
  14. <image :src="item.content" class="grace-editor-img" :data-index="index" mode="widthFix" @tap="deleteItem"></image>
  15. <view class="grace-editor-img-error" v-if="item.error">
  16. <view class="grace-flex-center">
  17. <text class="grace-editor-img-error-text grace-red" style="font-size:32rpx;">图片上传失败!</text>
  18. </view>
  19. <view class="grace-flex-center grace-margin-top">
  20. <text class="grace-editor-img-error-text grace-green">点击发布按钮重新上传</text>
  21. <text class="grace-editor-img-error-text">或</text>
  22. <text class="grace-editor-img-error-text grace-red" :data-index="index" @tap.stop="deleteItem">删除图片</text>
  23. </view>
  24. </view>
  25. </view>
  26. <!-- 引用 -->
  27. <textarea class="grace-editor-quote" maxlength="-1" :data-index="index" v-else-if="item.type == 'quote'"
  28. @input="graceEditorInput" :value="item.content" placeholder="# 请在此处输入引用内容" auto-height />
  29. <!-- 加粗 -->
  30. <textarea class="grace-editor-strong" :data-index="index" maxlength="-1" v-else-if="item.type == 'strong'"
  31. @input="graceEditorInput" :value="item.content" placeholder="# 请在此处输入加粗内容" auto-height />
  32. <!-- 链接 -->
  33. <input type="text" class="grace-editor-link" :data-index="index" v-else-if="item.type == 'link'"
  34. @input="graceEditorInput" :value="item.content" placeholder="# 输入连接地址" />
  35. <!-- 分割 -->
  36. <text class="grace-editor-spline" :data-index="index" @tap="deleteItem" v-else-if="item.type == 'spline'">● ● ●</text>
  37. </view>
  38. <!-- 选项类型选择 -->
  39. <view class="grace-space-between grace-editor-menus" :style="{paddingBottom:ipxHeight}">
  40. <view class="grace-editor-icons grace-icons icon-txt" data-type="txt" @tap="graceEditorAddItem"></view>
  41. <view class="grace-editor-icons grace-icons icon-center" data-type="center" @tap="graceEditorAddItem"></view>
  42. <view class="grace-editor-icons grace-icons icon-img" data-type="img" @tap="graceEditorAddItem"></view>
  43. <view class="grace-editor-icons grace-icons icon-quote" data-type="quote" @tap="graceEditorAddItem"></view>
  44. <view class="grace-editor-icons grace-icons icon-strong" data-type="strong" @tap="graceEditorAddItem"></view>
  45. <view class="grace-editor-icons grace-icons icon-link" data-type="link" @tap="graceEditorAddItem"></view>
  46. <view class="grace-editor-icons grace-icons icon-sp-line" data-type="spline" @tap="graceEditorAddItem"></view>
  47. </view>
  48. <!-- 底部占位 -->
  49. <view style="height:150rpx; width:100%"></view>
  50. </view>
  51. </template>
  52. <script>
  53. var systemInfo = require('../jsTools/systemInfo.js');
  54. export default{
  55. data() {
  56. return {
  57. article : {title:'', contents:[]},
  58. ipxHeight : 0
  59. }
  60. },
  61. created:function(){
  62. var system = systemInfo.info();
  63. // #ifdef H5
  64. this.ipxHeight = system.iPhoneXBottomHeightRpx + 'rpx';
  65. // #endif
  66. },
  67. methods:{
  68. graceEditorAddItem : function(e){
  69. var type = e.currentTarget.dataset.type;
  70. if(type == 'img'){
  71. uni.chooseImage({
  72. success:(e)=>{
  73. var imgs = e.tempFilePaths;
  74. for(let i = 0; i < imgs.length; i++){
  75. this.article.contents.push({type:type,content:imgs[i]});
  76. }
  77. this.returnArt();
  78. }
  79. });
  80. }else{
  81. this.article.contents.push({type:type,content:''});
  82. this.returnArt();
  83. }
  84. },
  85. graceEditorInput : function(e){
  86. var index = e.currentTarget.dataset.index;
  87. var val = e.detail.value;
  88. if(val == ''){
  89. this.article.contents.splice(index, 1);
  90. }else{
  91. this.article.contents[index].content = val;
  92. }
  93. this.returnArt();
  94. },
  95. deleteItem : function(e){
  96. var index = e.currentTarget.dataset.index;
  97. uni.showModal({
  98. title:"提示",
  99. content:"确定要删除项目吗?",
  100. success:(e)=>{
  101. if(e.confirm){this.article.contents.splice(index, 1); this.returnArt();}
  102. }
  103. })
  104. },
  105. returnArt : function(){
  106. this.$emit('change', this.article);
  107. },
  108. setError : function(index){
  109. this.article.contents[index].error = true;
  110. this.article.contents.splice(index, 1, this.article.contents[index]);
  111. },
  112. setDefault : function (article) {
  113. this.article = article;
  114. this.returnArt();
  115. }
  116. }
  117. }
  118. </script>
  119. <style>
  120. /* 编辑器 */
  121. .grace-editor{padding:10rpx 25rpx; width:700rpx;}
  122. .grace-editor-title{padding:25rpx 0; border-bottom:1px solid #F1F2F3; width:100%; font-size:36rpx; font-weight:bold; line-height:50rpx; background:none; color:#555555;}
  123. .grace-editor-menus{width:700rpx; position:fixed; z-index:1; left:0; background-color:#F8F8F8; bottom:0; border-top:1px solid #F1F2F3; padding:0 25rpx;}
  124. .grace-editor-icons{width:700rpx; height:88rpx; color:#666666; line-height:88rpx; text-align:center; font-size:38rpx !important;}
  125. .grace-editor-items{margin-top:10rpx; display:flex; flex-direction:row; justify-content:center;}
  126. .grace-editor-txt{background:none; width:700rpx; border:none; font-size:26rpx; line-height:36rpx; margin:15rpx 0;}
  127. .grace-editor-center{background:none; width:300rpx; text-align:center; border:none; font-size:28rpx; color:#333333; line-height:50rpx; padding:10rpx; border-bottom:1px solid #F5F6F8; font-weight:bold; min-height:50rpx;}
  128. .grace-editor-img-wrap{width:700rpx; height:300rpx; overflow:hidden; margin:10rpx 0; position:relative; font-size:0;}
  129. .grace-editor-img{width:700rpx;}
  130. .grace-editor-img-error{position:absolute; width:700rpx; height:300rpx; left:0; top:0; background-color:rgba(0,0,0,0.5); display:flex; flex-direction:column; align-items:center; justify-content:center;}
  131. .grace-editor-img-error-text{font-size:28rpx; margin:0 15rpx; color:#FFFFFF;}
  132. .grace-editor-quote{border:none; margin:8px 0; border-radius:8rpx; width:660rpx; color:#333333; background:#F8F8F8; line-height:38rpx; padding:15rpx 20rpx; font-size:26rpx;}
  133. .grace-editor-strong{width:700rpx; background:none; font-weight:bold; border:none; font-size:26rpx; line-height:36rpx; margin:15rpx 0;}
  134. .grace-editor-link{background:none; width:700rpx; border:none; font-size:26rpx; line-height:36rpx; margin:15rpx 0; color:#007AFF;}
  135. .grace-editor-spline{width:700rpx; line-height:60rpx; text-align:center; color:#8788A3; font-size:28rpx; opacity:0.6;}
  136. </style>