Files
jjx-web-sign-only/pages/user/components/news.vue
T
2026-10-08 18:20:51 +08:00

114 lines
3.7 KiB
Vue

<template>
<el-card>
<view class="flex justify-end items-center">
<el-button type="primary" @click="showAdd" v-if="!isAdd">新增新闻动态</el-button>
</view>
<view class="mt-20" v-if="isAdd">
<el-form ref="form" :model="form" label-width="120px">
<el-form-item label="标题" required>
<el-input v-model="form.title" placeholder="请输入标题"/>
</el-form-item>
<el-form-item label="内容">
<vk-data-input-editor v-model="form.content" width="750px"></vk-data-input-editor>
</el-form-item>
</el-form>
<view class="mt-30 flex justify-center items-center">
<el-button plain @click="cancel">取消</el-button>
<el-button type="primary" @click="addArticle">确定</el-button>
</view>
</view>
<view v-else>
<view class="py-20 border-bottom flex justify-between items-center" v-for="(item, index) in list"
:key="index">
<view class="flex flex-col justify-start items-start">
<text>{{ item.title }}</text>
<text class="mt-20 text-gray text-28">{{ item._add_time_str }}</text>
</view>
<view class="flex flex-col justify-end">
<el-button type="primary" size="small" @click="edit(item)">编辑</el-button>
<view class="mt-20">
<el-button type="primary" size="small" @click="del(item._id)" plain>删除</el-button>
</view>
</view>
</view>
</view>
</el-card>
</template>
<script>
export default {
name: "news",
data() {
return {
isAdd: false,
form: {
_id: null,
title: '',
content: '',
},
list: []
}
},
methods: {
async addArticle() {
if (!this.form.title) {
this.$message.error('请输入标题')
return
}
if (!this.form.content) {
this.$message.error('请输入内容')
return
}
await vk.callFunction({
url: 'client/userArticle/kh/action',
data: this.form
})
this.$message.success(this.form._id ? '修改成功' : '新增成功')
await this.getList()
this.isAdd = false
this.form = {
_id: null,
title: '',
content: '',
}
},
async getList() {
const {rows} = await vk.callFunction({
url: 'client/userArticle/kh/getList',
})
this.list = rows
},
del(_id) {
this.$confirm('确认删除该新闻动态吗?', '提示', {
confirmButtonText: '确定',
showCancelButton: false,
type: 'warning'
}).then(async () => {
await vk.callFunction({
url: 'client/userArticle/kh/delete',
data: {_id}
})
await this.getList()
})
},
edit(item) {
for (let key in this.form) this.form[key] = item[key]
this.isAdd = true
},
showAdd() {
this.isAdd = true
},
cancel(){
this.isAdd = !this.isAdd
this.form = {
_id: null,
title: '',
content: '',
}
}
},
mounted() {
this.getList()
}
}
</script>