Files
learning-system-mobile/pages/plus/editQuestion.vue
2022-11-17 17:13:36 +08:00

239 lines
5.2 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<!--添加文章-->
<view style="background-color: #fff;">
<u-toast ref="messager"></u-toast>
<!-- <page-title :showBack="true">编辑问题</page-title> -->
<view style="background-color: #fff;padding-top: 18rpx;">
<view class="bar-box">
<view class="bar-cancel" @click="toBack()">取消</view>
<view class="bar-center">编辑问题</view>
<view @click="goSubmit()" class="bar-go">提交</view>
</view>
<view class="content">
<view class="big-box-content">
<view class="row row-lin">
<u--input placeholder="请输入标题" placeholder-style="font-size:42upx;color:#c1c1c1;display:inline-block;white-space: pre-wrap; word-wrap: break-word;height: auto;
" 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:#666;font-weight: normal;" :height="300" count maxlength="500" v-model="content" placeholder="请输入正文"></u--textarea>
</view>
<view class="row">
<u-upload uploadIcon="plus" :fileList="fileList" multiple @afterRead="afterRead" @delete="deletePic" name="coverImg" :maxCount="5">
</u-upload>
</view>
</view>
</view>
</view>
<!-- <view style="margin-top: 20px;">
<view>
<u-button type="primary" text="提交问题"></u-button>
</view>
</view> -->
</view>
</template>
<script>
import apiQa from '@/api/modules/qa.js'
import uploadUtil from '@/utils/upload.js'
import { mapGetters } from 'vuex';
import apiStat from '@/api/phase2/stat.js'
export default {
data() {
return {
fileUrl:this.$config.fileUrl,
qa:{
content:'',
id:'',
title:'',
content:'',
images:''
},
fileList: [],
}
},
computed:{
...mapGetters(['userInfo']),
},
methods: {
toBack(){
uni.navigateBack();
},
goSubmit() {
let images=[];
this.fileList.forEach(file=>{
images.push(file.path);
})
this.qa.images=images.join();
uni.showLoading({title:'提交中...'})
apiQa.update(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
})
}else{
this.$refs.messager.show({message:rs.message,type:'error'});
setTimeout(function(){uni.hideLoading()},1000);
}
})
},
change(e) {
//没有任何处理打印console.log无意义
//console.log('change', e);
},
//删除图片
deletePic(event) {
this.fileList.splice(event.index, 1);
},
//新增图片
async afterRead(event) {
//当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
//console.log(event.file);
let $this=this;
event.file.forEach(img=>{
uploadUtil.uploadFile(img.url).then(rs=>{
//console.log(rs);
let item={
status: 'success',
message: '已上传',
path:rs.result.filePath,
url:rs.result.httpPath
}
this.fileList.push(item)
uni.hideLoading();
});
})
},
reverse() {
uni.navigateBack({
url: '/pages/plus/index'
})
}
},
onLoad(option){
if(option.value){
this.qa=JSON.parse(option.value)
this.content = (this.qa.content).replace(/<\/?[^>]*>/g, '');
}
},
}
</script>
<style lang="scss" scoped>
::v-deep .uni-textarea-textarea{
color: #666 !important;
}
::v-deep .uni-input-input{
font-size: 36upx !important;
font-weight: 500 !important;
color: #333333 !important;
}
.sub-box{
padding: 20rpx;
.sub-success{
.sub-title{
font-size: 40rpx;
font-weight: 500;
line-height: 45rpx;
margin-bottom: 10rpx;
padding: 20rpx;
}
.sub-text{
font-size: 30rpx;
line-height: 30rpx;
margin-bottom: 20rpx;
padding: 20rpx;
}
.sub-bar{
display: flex;
justify-content: space-between;
padding: 20rpx;
border-bottom: 2rpx solid #ccc;
.bar-time{
font-size: 26rpx;
color: #ccc;
}
}
.bar-reply{
text-align: center;
padding: 30rpx;
.field-icon{
display: block;
width: 40rpx;
margin: 0 auto;
}
}
.bar-cor{
height: 20rpx;
background-color: #ebebeb;
}
.bar-bon{
text-align: center;
min-height: 600rpx;
margin-top: 35rpx;
.bon-icon{
display: inline-block;
}
.bon-text{
display: inline-block;
margin-right: 10rpx;
}
}
}
}
.bar-box{
display: flex;
margin: 18rpx;
justify-content: space-between;
// position: relative;
.bar-cancel{
font-size: 32upx;
color: #7F7F7F;
font-family: Source Han Sans CN;
line-height: 36rpx;
}
.bar-center{
font-size: 36upx;
font-weight: 600;
color: #0D0D0D;
}
.bar-go{
// position: absolute;
// right: 18rpx;
color: #387DF7;
font-size: 32rpx;
font-family: Source Han Sans CN;
font-weight: bold;
line-height: 36rpx;
}
}
.row {
margin-bottom: 10rpx;
.row-input{
border: none;
}
}
.row-lin{
// border-top: 1px solid #eee;
border-bottom: 1px solid #eee;
}
.btn {
padding: 0px;
}
</style>