提问题

This commit is contained in:
lmj
2022-11-11 15:00:54 +08:00
parent 88339d6518
commit be72392b7d

View File

@@ -9,18 +9,25 @@
<!-- <view class="bar-center">提问题</view> -->
<view @click="goSubmit()" class="bar-go">提交</view>
</view>
<view class="content">
<view class="content" >
<view class="big-box-content">
<view class="row row-lin">
<u--input placeholder="请输入标题" placeholder-style="font-size:36upx;color:#c1c1c1;font-weight: normal;" maxlength="30" class="row-input" border="surround" v-model="qa.title" @change="change"></u--input>
</view>
<view class="row ">
<u--textarea class="row-input row-text" placeholder-style="font-size:42upx;color:#c1c1c1;font-weight: normal;" :height="300" count maxlength="500" v-model="qa.content" placeholder="请输入正文"></u--textarea>
<view class="row" style="min-height: 300upx !important;">
<!-- <u--textarea class="row-input row-text" placeholder-style="font-size:42upx;color:#c1c1c1;font-weight: normal;" :height="300" count maxlength="500" v-model="qa.content" placeholder="请输入正文"></u--textarea> -->
<editor id="editor" class="editor-content" placeholder="请输入正文"
:show-img-size="true"
:show-img-toolbar="true"
:show-img-resize="true"
@statuschange="onStatusChange"
@ready="onEditorReady">
</editor>
</view>
<!-- <view class="row">
<view v-if="qaimage" class="row">
<u-upload uploadIcon="plus" :fileList="fileList" multiple @afterRead="afterRead" @delete="deletePic" name="coverImg" :maxCount="1">
</u-upload>
</view> -->
</view>
</view>
</view>
</view>
@@ -65,6 +72,9 @@
export default {
data() {
return {
qaimage:false,
editorCtx: '',
formats: {},
fileUrl:this.$config.fileUrl,
qa:{
id:'',
@@ -76,28 +86,91 @@
}
},
methods: {
insertLabel(){
let $this=this;
this.editorCtx.getContents({
success(data) {
// 获取编辑器中的文本
let _html = data.html;
// 去掉文本中默认的标签
_html = _html.replace('<p><br></p>','');
// 接去掉文本中最后面的</p>标签
_html = _html.substring(0,_html.length-4);
// 重新拼接文本,并在末尾添加</p>标签
let html = `${_html}<span style="color: #3a8afb;"> #标签名#</span><i style="font-style: normal;"> </i></p>`;
// 给富文本设置内容
$this.editorCtx.setContents({html});
}
})
},
insertDate() {
const date = new Date()
const formatDate = `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`
this.editorCtx.insertText({
text: formatDate
})
},
insertImage() {
this.qaimage = true
},
//初始化富文本编辑器
onEditorReady() {
let $this=this;
/** #ifdef APP-PLUS || H5 ||MP-WEIXIN */
uni.createSelectorQuery().select('#editor').context((res) => {
//将内容写入编辑器
$this.editorCtx = res.context;
}).exec();
/** #endif */
},
onStatusChange(e){
const myFormats = e.detail;
this.formats = myFormats;
},
undo(){
this.editorCtx.undo()
},
redo(){
this.editorCtx.redo()
},
clear() {
this.editorCtx.clear({
success: function(res) {
console.log("clear success")
}
})
},
toBack(){
uni.navigateBack();
},
goSubmit() {
let $this=this;
let images=[];
this.fileList.forEach(file=>{
images.push(file.path);
})
this.qa.images=images.join();
$this.qa.images=images.join();
uni.showLoading({title:'提交中...'})
apiQa.save(this.qa).then(rs=>{
if(rs.status==200){
this.$refs.messager.show({message:'提交成功',type:'success'});
uni.redirectTo({
url:'/pages/resource/qaDetail?id='+rs.result.id
this.editorCtx.getContents({
success(res){
$this.qa.content=res.html;
apiQa.save($this.qa).then((rs)=>{
setTimeout(function(){uni.hideLoading()},1000);
if(rs.status==200){
$this.$refs.messager.show({message:'提交成功',type:'success'});
uni.redirectTo({
url:'/pages/resource/qaDetail?id='+rs.result.id
})
}else{
$this.$refs.messager.show({message:rs.message,type:'error'});
setTimeout(function(){uni.hideLoading()},1000);
}
})
}else{
this.$refs.messager.show({message:rs.message,type:'error'});
setTimeout(function(){uni.hideLoading()},1000);
}
})
},
change(e) {
//console.log('change', e);
@@ -140,6 +213,9 @@
</script>
<style lang="scss" scoped>
::v-deep .content{
height: 750upx !important;
}
.editor-btn{
padding: 0upx 12upx;
color: #656565;
@@ -213,8 +289,6 @@
display: flex;
margin: 18rpx;
justify-content: space-between;
// position: relative;
.bar-cancel{
font-size: 32upx;
color: #7F7F7F;
@@ -227,8 +301,6 @@
color: #0D0D0D;
}
.bar-go{
// position: absolute;
// right: 18rpx;
color: #588AFC;
font-size: 30rpx;
font-family: Source Han Sans CN;