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/index.vue

262 lines
5.8 KiB

11 months ago
<template>
<view class="article">
11 months ago
<view class="article-hd">
<view class="search">
<view class="box">
10 months ago
<image src="/static/news/icon-search.png" @click="getArticleList(1)"></image>
<input v-model="keyword" type="search" placeholder="请输入文章标题" />
11 months ago
</view>
11 months ago
<view class="add" @click="toDetail(2)">
11 months ago
<image src="/static/news/icon-add.png"></image>新增
</view>
</view>
11 months ago
<u-tabs :list="list" :is-scroll="false" v-model="current" @change="changeTab" active-color="#FF2525" inactive-color="#6F6F6F" font-size="30" ></u-tabs>
11 months ago
</view>
<view class="article-bd">
<u-swipe-action class="b" v-for="(a,i) in articleList" :index="i" :key="i" @click="clickItem" :options="options">
11 months ago
<view class="item u-border-bottom">
11 months ago
<view class="pic" @click.stop="toDetail(1,a)">
<image mode="aspectFill" :src="a.image_url" />
11 months ago
</view>
<!-- 此层wrap在此为必写的否则可能会出现标题定位错误 -->
11 months ago
<view class="info title-wrap" @click.stop="toDetail(1,a)">
<view class="title">{{a.title}}</view>
<view class="desc" v-html="a.content"></view>
11 months ago
</view>
</view>
</u-swipe-action>
11 months ago
</view>
<u-empty text="暂无信息" v-if="total == 0" mode="list"></u-empty>
11 months ago
</view>
</template>
<script>
10 months ago
import * as ArticleApi from '@/api/article'
11 months ago
export default {
data() {
return {
11 months ago
keyword: "",
isShow: false,
11 months ago
options: [
{
text: '编辑',
style: {
backgroundColor: '#FF8844'
}
},
{
text: '删除',
style: {
backgroundColor: '#FF564A'
}
}
11 months ago
],
articleList: [],
list: [],
total: 1,
pageNum: 1,
current: 0
11 months ago
};
11 months ago
},
onShow() {
11 months ago
this.getCategoryList();
},
onReachBottom() {
if(this.articleList.length <= this.total){
uni.showLoading({
title:"加载中"
})
this.pageNum ++;
this.getArticleList();
}
},
methods: {
toDetail(index,a){
if(index == 1){
uni.navigateTo({
url: "/pages/news/article/detail?articleId="+a.article_id
})
}else if(index == 2){
uni.navigateTo({
url: "/pages/news/article/add?type=1"
})
}
},
changeTab(i){
uni.showLoading({
title:"加载中"
})
this.current = i
this.getArticleList(1);
11 months ago
},
async toDel(index,article_id){
10 months ago
const {status, message, data} = await ArticleApi.del({
11 months ago
article_id
});
if(status == 200){
uni.showToast({
title: "删除成功"
})
this.getArticleList(1);
11 months ago
}
},
// 获取文章分类数据
async getCategoryList(categoryId) {
10 months ago
const {status, message, data} = await ArticleApi.articleCatList();
11 months ago
if(status == 200){
this.list = data.list;
this.getArticleList(1);
11 months ago
}
},
/**
* 获取文章列表
*/
10 months ago
async getArticleList(type) {
if(type == 1){
this.pageNum = 1;
this.articleList = []
}
11 months ago
let {status, message, data} = await ArticleApi.list({
categoryId: this.list[this.current].category_id,
page: this.pageNum,
10 months ago
title: this.keyword
11 months ago
});
if(status == 200){
uni.hideLoading();
if(data.list.data && data.list.data.length > 0){
data.list.data.map(a=>{
a.show = false
})
}
this.articleList = this.articleList.concat(data.list.data)
this.total = data.list.total
}
},
clickItem(index, index1){
if(index1 == 0){
uni.navigateTo({
url: "/pages/news/article/add?type=2&articleId="+this.articleList[index].article_id
})
}else{
const that = this;
11 months ago
uni.showModal({
title: "温馨提示",
content: "确定要删除该信息?",
confirmColor: "#FF584D",
complete(res) {
if(res.confirm){
that.toDel(index,that.articleList[index].article_id);
11 months ago
}
}
})
}
},
11 months ago
}
}
</script>
<style lang="scss">
.article{
&-bd{
11 months ago
.uni-movable-area{
background-color: transparent !important;
}
11 months ago
}
}
</style>
<style lang="scss" scoped>
.article{
&-hd{
background-color: #fff;
padding-bottom:20rpx;
.search{
width: 750rpx;
padding: 25rpx 35rpx;
border-bottom: 1px solid #F7F7F7;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: space-between;
.add{
font-size: 24rpx;
font-weight: 500;
color: #FF584D;
margin-left: 20rpx;
image{
width: 40rpx;
height: 40rpx;
display: block;
}
}
.box{
padding: 15rpx 25rpx;
box-sizing: border-box;
display: flex;
align-items: center;
background: #F3F3F3;
border-radius: 60rpx;
flex: 1;
image{
width: 28rpx;
height: 28rpx;
margin-right: 22rpx;
}
input{
flex: 1;
font-size: 28rpx;
line-height: 30rpx;
}
}
}
}
&-bd{
padding-bottom: 20rpx;
overflow: hidden;
.b{
margin-top: 20rpx;
}
.item{
padding: 30rpx 45rpx;
overflow: hidden;
display: flex;
align-items: center;
.pic{
width: 200rpx;
height: 160rpx;
margin-right: 20rpx;
image{
width: 100%;
height: 100%;
border-radius: 10rpx;
}
}
.info{
flex: 1;
max-width: 430rpx;
.title{
height: 50rpx;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
font-size: 28rpx;
font-weight: 500;
color: #3B3B3B;
}
11 months ago
.desc{
font-size: 26rpx;
color: #999;
height: 100rpx;
line-height: 50rpx;
11 months ago
word-break: break-all;
text-overflow: ellipsis;
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
11 months ago
}
11 months ago
}
}
}
}
</style>