Commit 932a0316 authored by Davve's avatar Davve

完成帖子创建编辑后端逻辑

parent ba219b88
......@@ -3,6 +3,7 @@
# __author__ = "chenwei"
# Date: 2018/11/16
from django.conf import settings
from utils.base import APIView
......@@ -95,7 +96,7 @@ class LoginView(APIView):
username = request.POST.get('username')
password = request.POST.get('password')
if username == 'admin' and password == '123123':
if username == settings.USERNAME and password == settings.PASSWORD:
data = {
'id': 1,
'roles': ['admin'],
......
......@@ -5,7 +5,7 @@
import datetime
from utils.base import APIView
from utils.time_utils import utc_to_datetime, datetime_toString, unix_time_to_datetime, analysis_time
from utils.time_utils import utc_to_datetime, unix_time_to_datetime, analysis_time
class PushListView(APIView):
......@@ -31,10 +31,8 @@ class PushUpdateOrCreateView(APIView):
def post(self, request):
id = request.POST.get('id', '')
try:
push_time = unix_time_to_datetime(int(request.POST.get('push_time', 0)) / 1000)
except ValueError:
push_time = utc_to_datetime(request.POST.get('push_time', '')[:-5] + 'Z')
push_time = analysis_time(request.POST.get('push_time', 0))
data = {
'url': request.POST.get('url', ''),
'push_time': push_time,
......
......@@ -3,32 +3,126 @@
# __author__ = "chenwei"
# Date: 2018/11/15
import json
from utils.base import APIView
from utils.time_utils import analysis_time
class TopicListView(APIView):
def get(self, request):
page = int(request.GET.get('page', 1))
page = int(request.GET.get('page', 0))
limit = int(request.GET.get('limit', 10))
filter = self.handle_filter(request.GET.get('filter', ""))
try:
data = self.rpc['venus/community/topic/get'](offset=page, limit=limit, filters=filter).unwrap()
data = self.rpc['venus/sun/topic/list'](offset=page, limit=limit, filters=filter).unwrap()
except Exception as e:
raise e
return data
class TopicUpdateOrCreateView(APIView):
def get(self, request):
id = request.GET.get('id')
try: # TODO 少返回了is_online
data = self.rpc['venus/sun/topic/get'](id=id).unwrap()
except Exception as e:
raise e
return {'data': data}
def post(self, request):
id = request.POST.get('id', '')
posting_time = analysis_time(request.POST.get('posting_time', 0))
topic_images = list(map(lambda x: x[:-2], json.loads(request.POST.get('topic_images', []))))
data = {
'topic_images': topic_images,
'topic_ids': json.loads(request.POST.get('topic_ids', '')),
'video_url': request.POST.get('video_url', ''),
'posting_time': posting_time,
'content': request.POST.get('content', ''),
'content_level': request.POST.get('content_level', ''),
'group_name': request.POST.get('group_name', ''),
'user_id': request.POST.get('user_id', ''),
'star_name': request.POST.get('star_name', ''),
'tag_ids': json.loads(request.POST.get('tag_ids', [])),
}
try:
self.rpc['venus/sun/topic/edit'](id=id, data=data).unwrap()
except Exception as e:
raise e
return {
'message': '更新成功'
}
class ReplyUpdateOrCreateView(APIView):
def get(self, request):
id = request.GET.get('id')
page = int(request.GET.get('page', 0))
limit = int(request.GET.get('limit', 10))
filter = self.handle_filter(request.GET.get('filter', ""))
filter.update({'id': id})
try:
data = self.rpc['venus/sun/topic/reply/list'](offset=page, limit=limit, filters=filter).unwrap()
except Exception as e:
data = [
{
'id': 1,
'reply_name': '真好',
'be_reply_name': '王二',
'create_time': '2018-09-10 23:23:23',
'reply_type': '贴主的评论',
'content': '内容真好',
},
]
return {
'total': 10,
'data': data
}
def post(self, request):
reply_ids = json.loads(request.POST.get('reply_ids', []))
try:
self.rpc['venus/sun/topic/reply/batch_delete'](data=reply_ids).unwrap()
except Exception as e:
raise e
return {
'message': '操作成功'
}
class ReplyCreate(APIView):
def post(self, request):
data = {
'topic_id': request.POST.get('topic_id'),
'reply_name': request.POST.get('reply_name'),
'be_reply_name': request.POST.get('be_reply_name'),
'content': request.POST.get('content'),
}
try:
data = self.rpc['venus/sun/topic/reply/create'](data=data).unwrap()
"""
data = {
'id': 1,
'reply_type': 1,
'create_time': '2108-09-92 12:12:12',
'reply_name': 'xxxxx',
'be_reply_name': 'xxxxxx',
'content': '测试测试',
}
"""
except Exception as e:
# raise e
data = {
'total': 200,
'data':[
{"id": "1", "content": '内容', 'user_name': 'alex','newly_reply': '最新回复', 'group_name': '小组名', 'update_time': '2019-09-18 23:59:59',
'reported_time': '2019-09-18 23:59:59', 'is_online': 1, 'is_reported': 0},
{"id": "2", "content": '内容', 'newly_reply': '最新回复', 'group_name': '小组名', 'update_time': '2019-09-18 23:59:59',
'reported_time': '2019-09-18 23:59:59', 'user_name': 'alex','is_online': 0, 'is_reported': 0},
{"id": "3", "content": '内容', 'user_name': 'alex','newly_reply': '最新回复', 'group_name': '小组名', 'update_time': '2019-09-18 23:59:59',
'reported_time': '2019-09-18 23:59:59', 'is_online': 1, 'is_reported': 1},
{"id": "4", "content": '内容', 'user_name': 'alex','newly_reply': '最新回复', 'group_name': '小组名', 'update_time': '2019-09-18 23:59:59',
'reported_time': '2019-09-18 23:59:59', 'is_online': 1, 'is_reported': 1},
{"id": "5", "content": '内容', 'user_name': 'alex','newly_reply': '最新回复', 'group_name': '小组名', 'update_time': '2019-09-18 23:59:59',
'reported_time': '2019-09-18 23:59:59', 'is_online': 0, 'is_reported': 0},
]
'id': 6,
'reply_type': "贴住的评论",
'create_time': '2108-09-92 12:12:12',
'reply_name': 'xxxxx',
'be_reply_name': 'xxxxxx',
'content': '测试测试',
}
return data
return {'data': data}
......@@ -38,6 +38,11 @@ urlpatterns = [
# topic相关
url(r'topic/list$', TopicListView.as_view()),
url(r'topic/detail', TopicUpdateOrCreateView.as_view()),
url(r'topic/creacte', TopicUpdateOrCreateView.as_view()),
url(r'topic/reply/list', ReplyUpdateOrCreateView.as_view()),
url(r'topic/reply/batch_delete', ReplyUpdateOrCreateView.as_view()),
url(r'topic/reply/create', ReplyCreate.as_view()),
# star相关
url(r'star/list$', StarListView.as_view()),
......
......@@ -137,4 +137,8 @@ STATICFILES_DIRS = [
QINIU_ACCESS_KEY = "UPCOYIJkZOMcdd9FDzpBqYjzWUh55fBpVi3AhWpL"
QINIU_SECRET_KEY = "z5YvpDDSam_JE345Z8J_f3TufzelOW2VOGNoBl9e"
QINIU_HOST = "http://wanmeizhensuo.qiniudn.com/"
QINIU_SCOPE = 'wanmeizhensuo'
\ No newline at end of file
QINIU_SCOPE = 'wanmeizhensuo'
# 超级管理员
USERNAME = 'admin'
PASSWORD = 'admin'
\ No newline at end of file
......@@ -2,7 +2,7 @@ import request from '@/utils/request'
export function userSearch(name) {
return request({
url: '/search/user',
url: '/api/search/user',
method: 'get',
params: { name }
})
......
......@@ -19,13 +19,12 @@ export function OffLineOrOnLine(data) {
export function createRemark(data) {
return request({
url: '/api/topic/create_remark',
url: '/api/topic/reply/create',
method: 'post',
data
})
}
export function fetchTopic(id) {
return request({
url: '/api/topic/detail',
......@@ -33,3 +32,27 @@ export function fetchTopic(id) {
params: { id }
})
}
export function createTopic(data) {
return request({
url: '/api/topic/create',
method: 'post',
data
})
}
export function fetchReply(query) {
return request({
url: '/api/topic/reply/list',
method: 'get',
params: query
})
}
export function DelReply(data) {
return request({
url: '/api/topic/reply/batch_delete',
method: 'post',
data
})
}
......@@ -24,7 +24,7 @@ export default {
},
page: {
type: Number,
default: 1
default: 0
},
limit: {
type: Number,
......
......@@ -31,9 +31,6 @@ Mock.mock(/\/article\/create/, 'post', articleAPI.createArticle)
Mock.mock(/\/article\/update/, 'post', articleAPI.updateArticle)
// 搜索相关
Mock.mock(/\/search\/user/, 'get', remoteSearchAPI.searchUser)
// 账单相关
Mock.mock(/\/transaction\/list/, 'get', transactionAPI.getList)
export default Mock
......@@ -55,7 +55,7 @@ export default {
}
}
const validatePassword = (rule, value, callback) => {
if (value.length < 6) {
if (value.length < 5) {
callback(new Error('The password can not be less than 6 digits'))
} else {
callback()
......@@ -64,7 +64,7 @@ export default {
return {
loginForm: {
username: 'admin',
password: '123123'
password: 'admin'
},
loginRules: {
username: [{ required: true, trigger: 'blur', validator: validateUsername }],
......
......@@ -241,6 +241,7 @@
this.postForm.region = Assembledata(this.temparray['region'], this.postForm.region);
this.postForm.pick_group = Assembledata(this.temparray['pick_group'], this.postForm.pick_group);
}else{
this.postForm.region = this.postForm.region.join(',')
this.postForm.region = this.postForm.region.join(',')
this.postForm.pick_group = this.postForm.pick_group.join(',')
}
......
......@@ -11,6 +11,14 @@
<el-select v-model="listQuery.filter.is_reported" :placeholder="'举报'" clearable class="filter-item" style="width: 100px">
<el-option v-for="item in ReBooleanTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
</el-select>
<el-select v-model="listQuery.filter.is_puppet" :placeholder="'马甲'" clearable class="filter-item" style="width: 100px">
<el-option v-for="item in ReBooleanTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
</el-select>
<el-select v-model="listQuery.filter.content_level" :placeholder="'帖子星级'" clearable class="filter-item" style="width: 100px">
<el-option v-for="item in ContentLevelTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
</el-select>
<el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">创建</el-button>
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleOfflineOrOnline('offline')">下线</el-button>
......@@ -18,58 +26,64 @@
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleOfflineOrOnline('is_reported')">推荐</el-button>
</div>
<el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center"></el-table-column>
<el-table-column align="center" label="帖子ID " width="70">
<el-table-column type="selection" align="center"></el-table-column>
<el-table-column align="center" label="帖子ID " >
<template slot-scope="scope">
<router-link :to="'/pick/edit/'+scope.row.id" class="link-type">
<router-link :to="'/topic/edit/'+scope.row.id" class="link-type">
<span>{{ scope.row.id }}</span>
</router-link>
</template>
</el-table-column>
<el-table-column width="70px" align="center" label="用户">
<el-table-column align="center" label="用户">
<template slot-scope="scope">
<span>{{ scope.row.user_name }}</span>
<span>{{ scope.row.user.name }}</span>
</template>
</el-table-column>
<el-table-column width="204px" align="center" label="帖子详情">
<el-table-column align="center" label="帖子详情">
<template slot-scope="scope">
<span>{{ scope.row.content }}</span>
</template>
</el-table-column>
<el-table-column width="130px" align="center" label="最新回复">
<el-table-column align="center" label="最新回复">
<template slot-scope="scope">
<span>{{ scope.row.newly_reply }}</span>
</template>
</el-table-column>
<el-table-column width="80px" align="center" label="小组">
<el-table-column align="center" label="小组">
<template slot-scope="scope">
<span>{{ scope.row.group_name }}</span>
<span>{{ scope.row.group.name }}</span>
</template>
</el-table-column>
<el-table-column width="155px" align="center" label="更新时间">
<el-table-column align="center" label="更新时间">
<template slot-scope="scope">
<span>{{ scope.row.update_time }}</span>
</template>
</el-table-column>
<el-table-column width="155px" align="center" label="举报时间">
<el-table-column align="center" label="举报时间">
<template slot-scope="scope">
<span>{{ scope.row.reported_time? scope.row.reported_time: '无' }}</span>
</template>
</el-table-column>
<el-table-column width="70px" align="center" label="下线">
<el-table-column align="center" label="帖子星级">
<template slot-scope="scope">
<span>{{ scope.row.content_level }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="下线">
<template slot-scope="scope">
<el-tag :type="scope.row.is_online | isOnlineFilter">{{ scope.row.is_online==1 ? '是' : '否' }}</el-tag>
</template>
</el-table-column>
<el-table-column width="70px" align="center" label="推荐">
<el-table-column align="center" label="推荐">
<template slot-scope="scope">
<el-tag :type="scope.row.is_reported | isOnlineFilter">{{ scope.row.is_reported==1 ? '是' : '否' }}</el-tag>
</template>
......@@ -77,7 +91,7 @@
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" style="margin-left: 150px;" @pagination="getList" />
<pagination v-show="total>0" :total="total" :page="listQuery.page" :limit="listQuery.limit" style="margin-left: 150px;" @pagination="getList" />
</div>
</template>
......@@ -116,13 +130,15 @@ export default {
multipleSelection: [],
del_list: [],
listQuery: {
page: 1,
page: 0,
limit: 10,
filter: {
value: '',
key: '',
is_online: '',
is_reported: '',
complaints__isnull: '',
user__is_puppet: '',
content_level: ''
},
},
BooleanTypeOptions: [
......@@ -135,9 +151,15 @@ export default {
],
SearchTypeOptions:[
{'key': 'id', 'display_name': '帖子ID'},
{'key': 'group__name', 'display_name': '小组名称'},
{'key': 'content', 'display_name': '明星名称'},
]
{'key': 'content', 'display_name': '帖子内容'},
],
ContentLevelTypeOptions:[
{'key': 1, 'display_name': '星级一'},
{'key': 2, 'display_name': '星级二'},
{'key': 3, 'display_name': '星级三'},
{'key': 4, 'display_name': '星级四'},
{'key': 5, 'display_name': '星级五'},
],
}
},
created() {
......@@ -147,6 +169,7 @@ export default {
getList() {
this.listLoading = true
fetchList(this.listQuery).then(response => {
console.log(response.data.data)
this.list = response.data.data.data
this.total = response.data.data.total
this.listLoading = false
......@@ -184,7 +207,7 @@ export default {
})
},
handleFilter() {
this.listQuery.page = 1
this.listQuery.page = 0
this.getList()
},
handleCreate() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment