内容发布完成

This commit is contained in:
aixianling
2021-12-20 17:29:52 +08:00
parent 6d0810031d
commit 14e0cd8faf
6 changed files with 470 additions and 3 deletions

View File

@@ -0,0 +1,106 @@
<template>
<section class="AppContentManager">
<AiNewsList :list="list" :loadmore="loadmore" @select="showDetail">
<template #header>
<div flex>
<AiAreaPicker :areaId="user.areaId" @select="handleSelectArea" icon="Location2.png"/>
<u-search placeholder="请输入标题" :show-action="false" v-model="search.title" @search="current=1,getList()"/>
</div>
</template>
</AiNewsList>
<AiFixedBtn>
<div class="addBtn iconfont iconfont-iconfangda" @click="gotoAdd"/>
</AiFixedBtn>
</section>
</template>
<script>
import {mapState} from "vuex";
export default {
name: "AppContentManager",
appName: "内容发布",
computed: {
...mapState(['user']),
loadmore() {
return this.pages <= this.current ? 'loading ' : 'nomore'
}
},
data() {
return {
list: [],
current: 1,
pages: 0,
search: {}
}
},
onLoad(params) {
if (params.moduleId) {
this.moduleId = params.moduleId
this.getData(params.moduleId)
}
},
methods: {
getData(moduleId) {
let {current, search} = this
moduleId && this.$http.post("/app/appcontentinfo/list", null, {
params: {moduleId, current, size: 10, ...search}
}).then(res => {
if (res?.data) {
this.list = current > 1 ? [...this.list, ...res.data.records] : res.data.records
this.pages = res.data.pages
}
})
},
handleSelectArea(e) {
this.search.areaId = e.id
this.getData()
},
showDetail(row) {
uni.navigateTo({url: `./contentDetail?id=${row.id}`})
},
gotoAdd() {
uni.navigateTo({url: `./contentAdd?moduleId=${this.moduleId}`})
}
},
onReachBottom() {
this.current++;
this.getData()
},
}
</script>
<style lang="scss" scoped>
.AppContentManager {
::v-deep.location {
width: 60px;
height: 60px;
margin-right: 12px;
}
::v-deep .u-search {
margin-bottom: 0 !important;
padding-left: 60px;
box-shadow: none;
.u-content {
padding-left: 50px;
box-sizing: border-box;
}
}
.addBtn {
width: 96px;
height: 96px;
flex-shrink: 0;
background: #fff;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
font-size: 48px;
color: $uni-color-primary;
border-radius: 50%;
justify-content: center;
align-items: center;
display: flex;
}
}
</style>

View File

@@ -0,0 +1,89 @@
<template>
<section class="contentAdd">
<u-form ref="ContentForm" label-position="top" :model="form">
<u-form-item label="标题" prop="title" required>
<u-input v-model="form.title" placeholder="请输入最多30字" maxlength="30"/>
</u-form-item>
<u-form-item label="详情描述" prop="content">
<AiTextarea v-model="form.content" placeholder="请输入最多500字" :maxlength="500"/>
</u-form-item>
<u-form-item label="图片最多9张" class="files">
<AiUploader multiple :limit="9" :def.sync="form.fileList" action="/admin/file/add2"/>
</u-form-item>
</u-form>
<div flex class="submitBtn" @tap="submitForm">提交</div>
</section>
</template>
<script>
export default {
name: "contentAdd",
computed: {
isEdit() {
return !!this.$route.query?.id
},
},
data() {
return {
form: {
fileList: []
},
moduleId: ""
}
},
onLoad(params) {
this.moduleId = params.moduleId
this.getForm(params.id)
},
methods: {
getForm(id) {
id && this.$http.post(`/app/appcontentinfo/queryDetailById`, null, {
params: {id}
}).then(res => {
if (res?.data) {
this.form = {...res.data};
}
})
},
submitForm() {
if (!this.form.title) {
return this.$u.toast("标题请填写")
}
this.$refs.ContentForm?.validate(v => {
if (v) {
let {moduleId} = this
this.$http.post(`/app/appcontentinfo/addOrUpdate`, {moduleId, ...this.form}).then(res => {
if (res?.code == 0) {
this.$u.toast("提交成功!")
setTimeout(() => {
uni.navigateBack({})
}, 1000)
}
})
}
})
},
}
}
</script>
<style lang="scss" scoped>
.contentAdd {
.files {
margin-top: 24px;
}
.submitBtn {
position: fixed;
justify-content: center;
bottom: 0;
width: 100%;
height: 112px;
color: #fff;
background: $uni-color-primary;
font-size: 32px;
font-family: PingFangSC-Medium, PingFang SC;
}
}
</style>

View File

@@ -0,0 +1,38 @@
<template>
<section class="contentDetail">
<AiDetail :title="detail.title" :detail="detail" :props="props"/>
</section>
</template>
<script>
export default {
name: "contentDetail",
data() {
return {
detail: {title: "内容详情"},
props: {
count: "viewCount"
}
}
},
onLoad(params) {
params.id && this.getDetail(params.id)
},
methods: {
getDetail(id) {
this.$http.post(`/app/appcontentinfo/queryDetailById`, null, {
params: {id}
}).then(res => {
if (res?.data) {
this.detail = res.data
}
})
},
}
}
</script>
<style lang="scss" scoped>
.contentDetail {
}
</style>

View File

@@ -4,7 +4,7 @@
<div slot="btn" @tap="handleInit">
<slot v-if="$slots.default"/>
<div v-else class="areaSelector">
<image :src="icon" class="location"/>
<image :src="locationIcon" class="location"/>
<div v-text="currentArea.name"/>
</div>
</div>
@@ -35,6 +35,7 @@ export default {
areaId: {default: ''},
name: {default: ''},
all: Boolean,
icon: {default: "location.svg"}
},
computed: {
...mapState(['user']),
@@ -53,8 +54,8 @@ export default {
currentArea() {
return this.fullArea?.slice(-1)?.[0] || {}
},
icon() {
return this.$cdn + 'location.svg'
locationIcon() {
return this.$cdn + this.icon
},
},
data() {

122
src/components/AiDetail.vue Normal file
View File

@@ -0,0 +1,122 @@
<template>
<section class="AiDetail">
<AiTopFixed class="header">
<slot v-if="$slots.header" name="header"/>
<template v-else>
<b class="title" v-text="title"/>
<div flex class="bottomBar">
<span v-text="detail.createTime"/>
<div flex>
<u-icon name="eye" :label="detail.count||0" size="36"/>
<u-icon name="thumb-up" :label="detail.thumbsUp||0" size="36"/>
</div>
</div>
</template>
</AiTopFixed>
<div class="content">
<slot v-if="$slots.content" name="content"/>
<u-parse v-else :html="detail.content"/>
</div>
<div class="files">
<slot v-if="$slots.files" name="files"/>
<div v-else>
<div v-if="detail.images" flex class="wrap imageList">
<ai-image v-for="file in detail.images" :key="file.id" :src="file.url" preview/>
</div>
<div v-else-if="detail.files" class="fileList">
<div v-for="file in detail.files" :key="file.id" flex>
<ai-image :src="file.url"/>
<div class="info">
<span>{{ file.name }} </span>
<i>{{ file.fileSizeStr }}</i>
</div>
</div>
</div>
</div>
</div>
<div v-if="comment" class="comments">
</div>
</section>
</template>
<script>
import AiTopFixed from "./AiTopFixed";
import AiImage from "./AiImage";
export default {
name: "AiDetail",
components: {AiImage, AiTopFixed},
props: {
title: {default: ""},
detail: {default: () => ({})},
comment: Boolean
},
mounted() {
document.title = this.title
}
}
</script>
<style lang="scss" scoped>
.AiDetail {
height: 100vh;
.header {
.title {
font-weight: bold;
font-size: 48px;
}
.bottomBar {
justify-content: space-between;
margin-top: 16px;
color: #999;
.u-icon + .u-icon {
margin-left: 32px;
}
}
}
.content, .files {
padding: 32px;
background: #fff;
&.content {
margin-bottom: 20px;
}
}
.imageList {
justify-content: space-around;
.AiImage {
margin-right: 8px;
margin-bottom: 8px;
}
}
.fileList {
& > div {
margin-bottom: 8px;
}
.info {
flex: 1;
min-width: 0;
display: flex;
& > span {
flex: 1;
min-width: 0;
}
& > i {
flex-shrink: 0;
}
}
}
}
</style>

View File

@@ -0,0 +1,111 @@
<template>
<section class="AiNewsList">
<AiTopFixed class="header">
<slot name="header"/>
</AiTopFixed>
<slot v-if="$slots.content" name="content"/>
<div class="listPane" v-else-if="list.length>0">
<div class="card" v-for="item in list" :key="item.id" @click="$emit('select',item)">
<slot v-if="$slots.row" name="row" :row="item"/>
<div class="title" v-text="item[props.title]"/>
<div flex class="subTitle">
<div class="tag" v-text="item[props.type]"/>
<span class="fill" v-text="item[props.createTime]"/>
<div flex>
<div class="count" v-text="item[props.count]||0"/>
人看过
</div>
</div>
</div>
<u-loadmore :status="loadmore" color="#999" font-size="24"
margin-top="32" margin-bottom="80"/>
</div>
<div class="no-message" v-else>
<image src="https://cdn.cunwuyun.cn/wxAdmin/img/message.png"/>
<p>暂无数据</p>
</div>
</section>
</template>
<script>
export default {
name: "AiNewsList",
props: {
list: {default: () => []},
props: {
default: () => ({
title: 'title',
type: "type",
createTime: "createTime",
count: "count",
})
},
loadmore: {default: "loadmore"}
}
}
</script>
<style lang="scss" scoped>
.AiNewsList {
height: 100vh;
background: #f3f6f9;
.listPane {
padding: 24px 32px 36px;
.card {
background: #FFFFFF;
box-shadow: 0 0 8px 0 rgba(0, 0, 0, 0.02);
border-radius: 16px;
padding: 32px;
margin-bottom: 32px;
.title {
height: 50px;
font-size: 36px;
font-weight: 500;
color: #333333;
line-height: 50px;
margin-bottom: 24px;
}
.subTitle {
color: #999;
width: 100%;
.tag {
height: 48px;
background: #EEEEEE;
border-radius: 24px;
text-align: center;
line-height: 48px;
margin-right: 16px;
}
.count {
color: #4181FF;
}
}
}
}
.no-message {
margin-top: 140px;
text-align: center;
color: #888;
font-size: 30px;
b {
font-size: 32px;
color: $uni-color-primary;
padding: 0 8px;
}
image {
width: 320px;
height: 240px;
}
}
}
</style>