You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong_qianduan/pages/news/article/add.vue

501 lines
11 KiB

10 months ago
<template>
<view class="goods">
<view class="goods-hd">
<view class="item">
<view class="a">文章标题<text>*</text></view>
<view class="b">
10 months ago
<input v-model="detail.title" placeholder="请输入文章标题" type="text"/>
10 months ago
</view>
</view>
<view class="item">
<view class="a">文章分类<text>*</text></view>
10 months ago
<view class="b" @click="openPage(1)">
<view class="select" :class="tabMIndex>= 0?'select-on':''">{{tabMIndex>=0? list[tabMIndex].name:'请输入分类名称'}}<u-icon name="arrow-right"></u-icon></view>
10 months ago
</view>
</view>
<view class="items">
<view class="a">封面图片<text>*</text></view>
<view class="c">
10 months ago
<u-upload :action="action" :header="header" @on-uploaded="success" width="180" height="180" :file-list="fileList" :custom-btn="true" max-count="1">
10 months ago
<template v-slot:addBtn>
<view class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
<image :src="$picUrl+'/static/news/icon-upload.png'"></image>
10 months ago
<view class="1">上传图片</view>
</view>
</template>
</u-upload>
</view>
</view>
<view class="items">
<view class="a">文章内容<text>*</text></view>
<view class="b">
<editor id="editor" class="ql-container" placeholder="开始输入..." show-img-size show-img-toolbar
show-img-resize @statuschange="onStatusChange" @input="inputEditor" :read-only="readOnly" @ready="onEditorReady">
10 months ago
</editor>
</view>
</view>
</view>
<view class="goods-fd">
10 months ago
<view class="btn" @click="toSubmit()">保存</view>
10 months ago
</view>
<u-popup v-model="isShow" mode="bottom" border-radius="12" mask-close-able="false" closeable>
<view class="goods-classify">
<view class="goods-classify-hd">
<view class="a" @click="openPage(4)"><u-icon name="plus"></u-icon></view></view>
10 months ago
<view class="goods-classify-bd">
<scroll-view scroll-y class="m">
<view class="item" v-for="(a,i) in list" @click="tabMItem(i,a.category_id)"><view :class="tabMIndex == i?'item-on':''">{{a.name}}</view></view>
10 months ago
</scroll-view>
</view>
</view>
</u-popup>
</view>
</template>
10 months ago
<script>
10 months ago
import Config from '@/core/config'
10 months ago
import * as ArticleApi from '@/api/article'
import * as CategoryApi from '@/api/article/category'
10 months ago
export default {
data() {
return {
10 months ago
action: "",
fileList: [],
10 months ago
detail: {},
10 months ago
formats: {},
10 months ago
isShow: false,
10 months ago
checked: false,
value: "",
popupType: 1,
10 months ago
tabMIndex: -1,
type: -1,
articleId: '',
clickFlag: true,
10 months ago
};
},
10 months ago
onLoad(o) {
console.log(o)
this.articleId = o.articleId;
10 months ago
this.type = o.type;
10 months ago
uni.setNavigationBarTitle({
title: !this.articleId?'新增文章':'编辑文章'
10 months ago
})
if(this.articleId){
10 months ago
this.getArticleDetail();
}else {
this.getCategoryList();
10 months ago
}
},
10 months ago
onReady() {
this.action = (Config.get('apiUrl')+'upload/image').replace("index.php?s=/","")
10 months ago
this.header = {
'Storeid': uni.getStorageSync('Store').storeInfo.store_id,
'Access-Token': uni.getStorageSync('AccessToken'),
10 months ago
'platform': "MP-WEIXIN",
}
uni.$on("reloadClasssify",this.getCategoryList())
10 months ago
},
10 months ago
methods: {
//接受上传返回的数据
success(list) {
if(list.length > 0){
const {response} = list[0];
if(response.status == 200){
uni.showToast({
title: "上传成功"
})
this.detail.image_id = response.data.fileInfo.file_id
}
}
10 months ago
},
10 months ago
// 获取文章详情
async getArticleDetail() {
const that = this;
10 months ago
const {status, message, data} = await ArticleApi.detail(this.articleId);
if(status == 200){
this.detail = data.detail
if( data.detail.image_url){
this.fileList = [{
url: data.detail.image_url
}]
}
setTimeout(()=>{
if(that.editorCtx){
that.editorCtx.setContents({
html: data.detail.content
})
}
},500)
this.getCategoryList(1);
10 months ago
}
10 months ago
},
10 months ago
// 获取文章分类数据
async getCategoryList(type) {
const that = this;
10 months ago
const {status, message, data} = await CategoryApi.list();
if(status == 200){
if(type == 1){
if(data.list && data.list.length > 0){
data.list.map((a,i)=>{
if(a.category_id == that.detail.category_id){
that.tabMIndex = i
}
})
}
}
10 months ago
this.list = data.list;
}
},
//提交修改
async toSubmit(){
10 months ago
if(!this.detail.title){
uni.showToast({
icon: "none",
title: "文章标题不能为空!"
})
return ;
}
if(!this.detail.category_id){
uni.showToast({
icon: "none",
title: "请选择分类!"
})
return ;
}
if(!this.detail.image_id){
uni.showToast({
icon: "none",
title: "请上传封面!"
})
return ;
}
if(!this.detail.content){
uni.showToast({
icon: "none",
title: "文章内容不能为空!"
})
return ;
}
if(this.clickFlag == false){
return ;
}
this.clickFlag = false
const { status, message } = this.articleId? await ArticleApi.edit({
article_id: this.articleId,
title: this.detail.title,
category_id: this.detail.category_id,
image_id: this.detail.image_id,
content: this.detail.content,
sort: 2,
status: 1
}):await ArticleApi.add({
title: this.detail.title,
category_id: this.detail.category_id,
image_id: this.detail.image_id,
content: this.detail.content,
sort: 2,
status: 1
});
if(status == 200){
this.clickFlag = true
uni.showToast({
title: "提交成功"
})
setTimeout(()=>{
uni.navigateBack({
delta: 1
})
},2000)
}else{
this.clickFlag = true
uni.showToast({
icon: "none",
title: message
})
}
},
inputEditor(e) {
this.detail.content = e.detail.html
10 months ago
},
10 months ago
onStatusChange(e) {
const formats = e.detail
this.formats = formats
},
onEditorReady() {
uni.createSelectorQuery().select('#editor').context((res) => {
this.editorCtx = res.context
}).exec()
10 months ago
},
openPage(i){
10 months ago
if(i == 1){
10 months ago
this.isShow = true;
}else if(i == 4){
this.isShow = false;
10 months ago
uni.navigateTo({
url: "/pages/news/article/classify"
10 months ago
})
}
},
tabMItem(index,category_id) {
10 months ago
this.tabMIndex = index;
this.detail.category_id = category_id
10 months ago
this.isShow = false;
10 months ago
},
}
}
</script>
<style lang="scss" scoped>
.goods{
.ql-container {
10 months ago
box-sizing: border-box;
width: 100%;
color: #212121;
font-size: 26rpx;
overflow: auto;
padding: 10rpx 10rpx 20rpx 10rpx;
border: 1px solid #ECECEC;
10 months ago
}
padding: 0 0 130rpx;
overflow: hidden;
&-hd{
background-color: #fff;
padding: 0 25rpx 0;
overflow: hidden;
margin-bottom: 20rpx;
.item{
padding: 20rpx 30rpx;
line-height: 50rpx;
font-size: 28rpx;
color: #212121;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid #F7F7F7;
.a{
text{
color: #F34A40;
margin-left: 5rpx;
}
}
.b{
font-size: 28rpx;
color: #212121;
display: flex;
align-items: center;
justify-content: flex-end;
flex: 1;
input{
font-size: 28rpx;
color: #212121;
flex: 1;
line-height: 50rpx;
font-size: 28rpx;
color: #212121;
text-align: right;
margin-right: 10rpx;
}
.select{
width: 100%;
display: flex;
align-items: center;
color: #C7C7C7;
justify-content: flex-end;
&-on{
color: #212121;
}
}
}
}
.items{
padding: 20rpx 30rpx;
line-height: 50rpx;
font-size: 28rpx;
color: #212121;
border-bottom: 1px solid #F7F7F7;
position: relative;
.a{
flex: 1;
display: flex;
align-items: center;
input{
flex: 1;
font-size: 26rpx;
color: #212121;
line-height: 50rpx;
margin-left: 20rpx;
}
text{
color: #F34A40;
margin-left: 5rpx;
}
.select{
flex: 1;
}
.tip{
margin-left: 15rpx;
font-size: 24rpx;
font-weight: 500;
color: #9F9F9F;
}
}
.b{
padding-top: 10rpx;
font-size: 24rpx;
font-weight: 400;
color: #C7C7C7;
}
.d{
position: absolute;
right: 20rpx;
top: 20rpx;
z-index: 2;
font-size: 28rpx;
font-weight: 400;
color: #212121;
}
.c{
padding-top: 20rpx;
overflow: hidden;
.slot-btn{
width: 180rpx;
height: 180rpx;
background: #F6F6F6;
border-radius: 10rpx;
border: 1px solid #C0C0C0;
text-align: center;
font-size: 28rpx;
font-weight: 500;
color: #6D6D6D;
.l{
line-height: 30rpx;
}
image{
width: 50rpx;
height: 50rpx;
display: block;
margin: 0 auto;
margin-top: 30rpx;
}
}
}
}
}
&-fd{
width: 100%;
position: fixed;
left: 0;
bottom: 0;
padding: 30rpx;
z-index: 99;
background-color: #fafafa;
box-sizing: border-box;
.btn{
width: 630rpx;
line-height: 88rpx;
background: #F34A40;
border-radius: 88rpx;
text-align: center;
font-size: 28rpx;
font-weight: 500;
color: #FFFFFF;
10 months ago
margin: 0 auto;
10 months ago
}
}
&-classify{
width: 100%;
overflow: hidden;
&-hd{
padding: 30rpx 60rpx;
position: relative;
font-size: 32rpx;
font-weight: 500;
color: #303030;
text-align: center;
.a{
display: flex;
align-items: center;
font-size: 28rpx;
font-weight: 500;
color: #FF624F;
position: absolute;
top: 30rpx;
left: 40rpx;
z-index: 2;
}
}
&-bd{
overflow: hidden;
display: flex;
align-items: flex-start;
.l{
width: 210rpx;
height: 560rpx;
background-color: #F7F8FA;
.item{
text-overflow: ellipsis;
overflow: hidden;
height: 70rpx;
font-size: 28rpx;
font-weight: 400;
color: #303030;
white-space: nowrap;
line-height: 70rpx;
padding-left: 30rpx;
box-sizing: border-box;
10 months ago
text-align: left;
10 months ago
&-on{
background-color: #fff;
font-weight: 500;
}
}
}
.m{
width: 100%;
text-align: center;
max-height: 560rpx;
.item{
text-overflow: ellipsis;
overflow: hidden;
height: 70rpx;
font-size: 28rpx;
font-weight: 400;
color: #303030;
white-space: nowrap;
line-height: 70rpx;
padding-left: 80rpx;
box-sizing: border-box;
text-align: left;
&-on{
color: #FF624F;
}
}
}
.r{
width: 540rpx;
height: 560rpx;
.item{
text-overflow: ellipsis;
overflow: hidden;
height: 70rpx;
font-size: 28rpx;
font-weight: 400;
color: #303030;
white-space: nowrap;
line-height: 70rpx;
padding-left: 80rpx;
box-sizing: border-box;
&-on{
color: #FF624F;
}
}
}
}
}
}
</style>