article
This commit is contained in:
parent
48c4edb7ea
commit
17f68ef261
|
@ -32,3 +32,9 @@ export function getArticle(id) {
|
|||
method: 'get',
|
||||
})
|
||||
}
|
||||
export function topArticle(id) {
|
||||
return request({
|
||||
url: `/cms/article/${id}/top/`,
|
||||
method: 'put',
|
||||
})
|
||||
}
|
||||
|
|
|
@ -69,6 +69,9 @@
|
|||
<el-table-column align="left" label="消费者">
|
||||
<template slot-scope="scope">{{ scope.row.consumer_name }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="left" label="单位">
|
||||
<template slot-scope="scope">{{ scope.row.consumer_company_name }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="left" label="工作类别">
|
||||
<template slot-scope="scope">{{ scope.row.workscope_name }}</template>
|
||||
</el-table-column>
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
</el-select> -->
|
||||
<el-input
|
||||
v-model="listQuery.search"
|
||||
placeholder="姓名或手机号"
|
||||
placeholder="姓名/手机号/单位"
|
||||
style="width: 200px;"
|
||||
class="filter-item"
|
||||
@keyup.enter.native="handleFilter"
|
||||
|
|
|
@ -33,6 +33,15 @@
|
|||
<el-table-column align="left" label="标题">
|
||||
<template slot-scope="scope">{{ scope.row.title }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="left" label="来源">
|
||||
<template slot-scope="scope">{{ scope.row.ifrom }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="left" label="外链">
|
||||
<template slot-scope="scope">
|
||||
{{ scope.row.elink }}
|
||||
<el-tag v-if="!scope.row.elink">原创</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="left" label="新建时间">
|
||||
<template slot-scope="scope">{{ scope.row.create_time }}</template>
|
||||
</el-table-column>
|
||||
|
@ -41,6 +50,22 @@
|
|||
</el-table-column>
|
||||
<el-table-column align="center" label="操作">
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
v-show="scope.row.is_top"
|
||||
type="danger"
|
||||
size="small"
|
||||
@click="handleTop(scope)"
|
||||
icon=""
|
||||
:disabled="!checkPermission(['article_top'])"
|
||||
>取消置顶</el-button>
|
||||
<el-button
|
||||
v-show="!scope.row.is_top"
|
||||
type="primary"
|
||||
size="small"
|
||||
@click="handleTop(scope)"
|
||||
icon="el-icon-upload2"
|
||||
:disabled="!checkPermission(['article_top'])"
|
||||
>置顶</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
size="small"
|
||||
|
@ -69,7 +94,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { getArticleList, deleteArticle } from "@/api/cms";
|
||||
import { getArticleList, deleteArticle, topArticle } from "@/api/cms";
|
||||
import checkPermission from "@/utils/permission";
|
||||
import Pagination from "@/components/Pagination";
|
||||
|
||||
|
@ -140,6 +165,19 @@ export default {
|
|||
}).catch(() => {
|
||||
});
|
||||
},
|
||||
handleTop(scope) {
|
||||
topArticle(scope.row.id).then(response => {
|
||||
if(response.code>=200){
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!'
|
||||
});
|
||||
this.getList()
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
|
@ -14,7 +14,10 @@
|
|||
<el-form-item label="来源" prop="ifrom">
|
||||
<el-input v-model="Form.ifrom" style="width: 500"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="内容" prop="content">
|
||||
<el-form-item label="外部链接" prop="elink" >
|
||||
<el-input v-model="Form.elink" style="width: 500"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="内容" prop="content" v-show="is_show">
|
||||
<tinymce v-model="Form.content" :height="400" :width="600"/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
|
@ -39,6 +42,7 @@ export default {
|
|||
Form:{
|
||||
title:'',
|
||||
ifrom:'',
|
||||
elink:'',
|
||||
content:''
|
||||
},
|
||||
submitLoding: false,
|
||||
|
@ -49,12 +53,13 @@ export default {
|
|||
ifrom: [
|
||||
{ required: true, message: "请输入", trigger: "blur" }
|
||||
],
|
||||
content: [
|
||||
{ required: true, message: "请输入", trigger: "blur" }
|
||||
],
|
||||
},
|
||||
is_show: true
|
||||
}
|
||||
},
|
||||
watch:{
|
||||
'Form.elink':'showEditor'
|
||||
},
|
||||
methods:{
|
||||
goBack() {
|
||||
this.$router.go(-1)
|
||||
|
@ -80,6 +85,14 @@ export default {
|
|||
}
|
||||
});
|
||||
},
|
||||
showEditor(){
|
||||
if(this.Form.elink){
|
||||
this.Form.content = ''
|
||||
this.is_show = false
|
||||
}else{
|
||||
this.is_show = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -14,7 +14,10 @@
|
|||
<el-form-item label="来源" prop="ifrom">
|
||||
<el-input v-model="Form.ifrom" style="width: 500"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="内容" prop="content">
|
||||
<el-form-item label="外部链接" prop="elink" >
|
||||
<el-input v-model="Form.elink" style="width: 500"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="内容" prop="content" v-show="is_show">
|
||||
<tinymce v-model="Form.content" :height="400" :width="600"/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
|
@ -39,6 +42,7 @@ export default {
|
|||
Form:{
|
||||
title:'',
|
||||
ifrom:'',
|
||||
elink:'',
|
||||
content:''
|
||||
},
|
||||
submitLoding: false,
|
||||
|
@ -49,16 +53,17 @@ export default {
|
|||
ifrom: [
|
||||
{ required: true, message: "请输入", trigger: "blur" }
|
||||
],
|
||||
content: [
|
||||
{ required: true, message: "请输入", trigger: "blur" }
|
||||
],
|
||||
},
|
||||
is_show: false
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.Form.id = this.$route.query.id //接收参数
|
||||
this.getArticle();
|
||||
},
|
||||
watch:{
|
||||
'Form.elink':'showEditor'
|
||||
},
|
||||
methods:{
|
||||
goBack() {
|
||||
this.$router.go(-1)
|
||||
|
@ -89,6 +94,14 @@ export default {
|
|||
this.Form = response.data ;
|
||||
});
|
||||
},
|
||||
showEditor(){
|
||||
if(this.Form.elink){
|
||||
this.Form.content = ''
|
||||
this.is_show = false
|
||||
}else{
|
||||
this.is_show = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -56,9 +56,9 @@ App({
|
|||
globalData: {
|
||||
userInfo: null,
|
||||
userinfo: null, // 服务器传回的消费者信息
|
||||
host: 'https://apitest.ctcshe.com',
|
||||
// host: 'https://apitest.ctcshe.com',
|
||||
mediahost: 'https://apitest.ctcshe.com',
|
||||
//host: 'http://127.0.0.1:8000',
|
||||
host: 'http://127.0.0.1:8000',
|
||||
//mediahost: 'http://127.0.0.1:8000',
|
||||
token : '',
|
||||
}
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
"pages/my/index",
|
||||
"pages/collect/main",
|
||||
"pages/workscope/index",
|
||||
"pages/yati/index"
|
||||
"pages/yati/index",
|
||||
"pages/article/index",
|
||||
"pages/article/detail"
|
||||
],
|
||||
"window": {
|
||||
"backgroundTextStyle": "light",
|
||||
|
@ -39,11 +41,17 @@
|
|||
"selectedIconPath": "images/homec.png",
|
||||
"text": "主页"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/article/index",
|
||||
"iconPath": "images/icon_doc.png",
|
||||
"selectedIconPath": "images/icon_doc_fill.png",
|
||||
"text": "资讯"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/my/index",
|
||||
"iconPath": "images/me.png",
|
||||
"selectedIconPath": "images/mec.png",
|
||||
"text": "个人中心"
|
||||
"text": "我的"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
|
@ -0,0 +1,75 @@
|
|||
// pages/article/detail.js
|
||||
const api = require("../../utils/request.js");
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (options) {
|
||||
this.getDetail(options.id)
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {
|
||||
|
||||
},
|
||||
|
||||
getDetail: function (id) {
|
||||
var that = this
|
||||
api.request(`/cms/article/${id}/`,'GET').then(res => {
|
||||
that.setData(res.data)
|
||||
})
|
||||
},
|
||||
|
||||
})
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"usingComponents": {}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<web-view wx:if="{{elink}}" src="{{elink}}"></web-view>
|
||||
<view class="page" wx:else>
|
||||
<view class="page__hd" style="padding:20px">
|
||||
<view class="page__title" >{{title}}</view>
|
||||
<view class="page__desc">
|
||||
<span style="font-weight:bold;color:darkblue;font-size:16px">{{ifrom}} </span>
|
||||
<text class="weui-badge" style="background:orange" wx:if="{{is_top}}">置顶</text>
|
||||
<text class="weui-badge" style="background:green">原创</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="page__bd">
|
||||
<view class="weui-article">
|
||||
<rich-text nodes="{{content}}"></rich-text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
|
@ -0,0 +1 @@
|
|||
/* pages/article/detail.wxss */
|
|
@ -0,0 +1,100 @@
|
|||
// pages/lianxi/index.js
|
||||
const api = require("../../utils/request.js");
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
results: [],
|
||||
query: {
|
||||
page: 1,
|
||||
limit: 10
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function () {
|
||||
var that = this
|
||||
that.getList(that.data.query)
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function () {
|
||||
},
|
||||
getList: function () {
|
||||
var that = this
|
||||
api.request('/cms/article/', 'GET', that.data.query).then(res => {
|
||||
if (that.data.query.page == 1) {
|
||||
that.data.results = res.data.results
|
||||
} else {
|
||||
that.data.results = that.data.results.concat(res.data.results)
|
||||
}
|
||||
|
||||
that.setData({
|
||||
results: that.data.results,
|
||||
count: res.data.count
|
||||
})
|
||||
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
var that = this
|
||||
that.data.query.page = 1;
|
||||
that.getList();
|
||||
wx.stopPullDownRefresh();
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
var that = this
|
||||
if (that.data.count <= that.data.query.page * that.data.query.limit) {
|
||||
wx.showToast({
|
||||
title: '没有更多了',
|
||||
icon: 'none'
|
||||
})
|
||||
} else {
|
||||
that.data.query.page = that.data.query.page + 1
|
||||
that.getList()
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {
|
||||
|
||||
},
|
||||
|
||||
})
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"usingComponents": {}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<view class="head">
|
||||
|
||||
{{count}}条资讯</view>
|
||||
<view class="weui-cells weui-cells_after-title">
|
||||
<block wx:for="{{results}}" wx:key="unique">
|
||||
<navigator url="detail?id={{item.id}}" class="weui-media-box weui-media-box_appmsg" hover-class="weui-cell_active">
|
||||
<view class="weui-media-box__bd weui-media-box__bd_in-appmsg">
|
||||
<view class="weui-media-box__title">
|
||||
<text class="weui-badge" style="background:orange" wx:if="{{item.is_top}}">置顶</text>
|
||||
{{item.title}}</view>
|
||||
<view class="weui-media-box__desc">
|
||||
来源:
|
||||
<span style="font-weight:bold;color:darkblue">{{item.ifrom}}</span>
|
||||
{{item.update_time}}
|
||||
</view>
|
||||
</view>
|
||||
<view class="weui-panel__ft weui-cell__ft_in-access">
|
||||
<view class="weui-media-box__desc">查看详情</view>
|
||||
</view>
|
||||
</navigator>
|
||||
</block>
|
||||
</view>
|
|
@ -0,0 +1,5 @@
|
|||
.head{
|
||||
color:#fff;
|
||||
background-color: cornflowerblue;
|
||||
text-align: center;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.0.4 on 2020-04-29 01:44
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cms', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='article',
|
||||
name='frame',
|
||||
field=models.URLField(blank=True, null=True, verbose_name='外部链接'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='article',
|
||||
name='is_top',
|
||||
field=models.BooleanField(default=False, verbose_name='置顶'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.4 on 2020-04-29 03:47
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cms', '0002_auto_20200429_0944'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='article',
|
||||
old_name='frame',
|
||||
new_name='elink',
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.4 on 2020-04-29 04:05
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cms', '0003_auto_20200429_1147'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='article',
|
||||
name='content',
|
||||
field=models.TextField(blank=True, verbose_name='内容'),
|
||||
),
|
||||
]
|
|
@ -8,8 +8,10 @@ class Article(CommonModel):
|
|||
文章
|
||||
'''
|
||||
title = models.CharField(max_length=60, verbose_name='标题')
|
||||
content = models.TextField(verbose_name='内容')
|
||||
elink = models.URLField(verbose_name='外部链接', null=True, blank=True)
|
||||
content = models.TextField(verbose_name='内容', blank=True)
|
||||
ifrom = models.CharField(max_length=60, verbose_name='来源')
|
||||
is_top = models.BooleanField('置顶', default=False)
|
||||
|
||||
class Meta:
|
||||
verbose_name = '文章'
|
||||
|
|
|
@ -11,3 +11,13 @@ class ArticelSerializer(serializers.ModelSerializer):
|
|||
class Meta:
|
||||
model = Article
|
||||
fields = '__all__'
|
||||
|
||||
class ArticelListSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
文章列表序列化
|
||||
"""
|
||||
create_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False, read_only=True)
|
||||
update_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False, read_only=True)
|
||||
class Meta:
|
||||
model = Article
|
||||
exclude = ('content',)
|
||||
|
|
|
@ -22,7 +22,7 @@ from rest_framework_jwt.settings import api_settings
|
|||
# Create your views here.
|
||||
|
||||
from .models import Article
|
||||
from .serializers import ArticelSerializer
|
||||
from .serializers import ArticelSerializer, ArticelListSerializer
|
||||
from utils.custom import CommonPagination
|
||||
class ArticleViewSet(ModelViewSet):
|
||||
"""
|
||||
|
@ -36,5 +36,21 @@ class ArticleViewSet(ModelViewSet):
|
|||
pagination_class = CommonPagination
|
||||
filter_backends = [DjangoFilterBackend,SearchFilter, OrderingFilter]
|
||||
search_fields = ('^title','^content')
|
||||
ordering_fields = ('id',)
|
||||
ordering = ['-id']
|
||||
ordering_fields = ('title','update_time')
|
||||
ordering = ['-is_top', '-update_time']
|
||||
|
||||
def get_serializer_class(self):
|
||||
if self.action=='list':
|
||||
return ArticelListSerializer
|
||||
else:
|
||||
return ArticelSerializer
|
||||
|
||||
@action(methods=['put'], detail=True, url_name='top_article', perms_map=[{'*':'top_article'}])
|
||||
def top(self, request, *args, **kwargs):
|
||||
'''
|
||||
置顶文章
|
||||
'''
|
||||
instance = self.get_object()
|
||||
instance.is_top = False if instance.is_top else True
|
||||
instance.save()
|
||||
return Response(status=status.HTTP_200_OK)
|
|
@ -12,6 +12,7 @@ ConsumerPerms = [
|
|||
'my_subjects',
|
||||
'my_examtest',
|
||||
'examtest_create',
|
||||
'article_list'
|
||||
]
|
||||
|
||||
class MyPermission(RbacPermission):
|
||||
|
|
|
@ -85,7 +85,7 @@ class ConsumerViewSet(ModelViewSet):
|
|||
ordering = ['-create_time']
|
||||
filter_backends = [DjangoFilterBackend, SearchFilter, OrderingFilter]
|
||||
filterset_fields = ('company',)
|
||||
search_fields = ('^name','^username')
|
||||
search_fields = ('^name','^username','^company__name')
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = self.queryset
|
||||
|
@ -202,10 +202,7 @@ class ConsumerViewSet(ModelViewSet):
|
|||
companyname = sheet['C'+str(m)].value
|
||||
if companyname:
|
||||
companyname = companyname.replace(' ', '')
|
||||
if companyname not in companydict:
|
||||
return Response({"error":"不存在单位("+companyname+")!请先新建"})
|
||||
else:
|
||||
companyobj = Company.objects.get(id=companydict[companyname])
|
||||
companyobj = Company.objects.get_or_create(id=companydict[companyname])[0]
|
||||
workscope = sheet['d'+str(m)].value
|
||||
if Consumer.objects.filter(username = username).exists():
|
||||
obj = Consumer.objects.filter(username = username).first()
|
||||
|
|
Loading…
Reference in New Issue