Commit ca033122 authored by Davve's avatar Davve

增加标签类型

parent cf0a6d09
......@@ -89,3 +89,15 @@ class TopicSearchView(APIView):
return {
'data': ['{id}:{name}'.format(id=search_data['id'], name=search_data['name']) for search_data in data]
}
class TagTypeSearchView(APIView):
def get(self, request):
name = request.GET.get('name')
try:
data = self.rpc['venus/sun/tag/tagtype_search'](name=name).unwrap()
except Exception as e:
raise e
return {
'data': ['{id}:{name}'.format(id=search_data['id'], name=search_data['name']) for search_data in data]
}
\ No newline at end of file
......@@ -56,12 +56,13 @@ class TagUpdateOrCreateView(APIView):
id = request.POST.get('id')
down_tags = list(set(map(lambda x: x.split(":")[0], json.loads((request.POST.get('down_tags', '[]'))))))
up_tags = list(set(map(lambda x: x.split(":")[0], json.loads((request.POST.get('up_tags', '[]'))))))
tagtypes = list(set(map(lambda x: x.split(":")[0], json.loads((request.POST.get('tagtypes', '[]'))))))
data = {
'name': request.POST.get('name'),
'description': request.POST.get('description'),
'down_tags': down_tags,
'up_tags': up_tags,
'tagtypes': tagtypes,
}
try:
data = self.rpc['venus/sun/tag/edit'](id=id, data=data).unwrap()
......@@ -69,3 +70,60 @@ class TagUpdateOrCreateView(APIView):
error_logger.error(u'创建/编辑标签%d信息失败%s' % (id, e))
raise
return data
class TagTypeListView(APIView):
def get(self, request):
offset = int(request.GET.get('offset', 1))
limit = int(request.GET.get('limit', 10))
filter = self.handle_filter(request.GET.get('filter', ""))
try:
data = self.rpc['venus/sun/tag/tagtype/list'](offset=(offset - 1) * limit, limit=limit, filters=filter).unwrap()
except Exception as e:
error_logger.error(u'获取标签类型列表失败%s', e)
raise
return data
def post(self, request):
ids = request.POST.get('ids', '').split()
update = int(request.POST.get('update', ''))
updates = {
'is_online': bool(update)
}
try:
self.rpc['venus/sun/tag/tagtype/batch/update'](updates=updates, ids=ids).unwrap()
except Exception as e:
error_logger.error(u'批量更新标签类型列表失败%s', e)
raise
return {
"message": "更新成功"
}
class TagTypeUpdateOrCreateView(APIView):
def get(self, request):
id = request.GET.get('id')
try:
data = self.rpc['venus/sun/tag/tagtype/get'](id=id).unwrap()
except Exception as e:
error_logger.error(u'获取标签%d信息失败%s'%(id, e))
raise
if not data:
data = {}
else:
pass
return {'data': data}
def post(self, request):
id = request.POST.get('id')
data = {
'name': request.POST.get('name'),
}
try:
data = self.rpc['venus/sun/tag/tagtype/edit'](id=id, data=data).unwrap()
except Exception as e:
error_logger.error(u'创建/编辑标签类型%d信息失败%s' % (id, e))
raise
return data
\ No newline at end of file
......@@ -53,6 +53,7 @@ class TopicUpdateOrCreateView(APIView):
'star_id': request.POST.get('star', '').split(':')[0],
'tag_ids': tag_ids,
'is_online': int(request.POST.get('is_online')),
'drop_score': int(request.POST.get('drop_score')),
}
try:
self.rpc['venus/sun/topic/edit'](id=id, data=data).unwrap()
......
......@@ -87,6 +87,12 @@ urlpatterns = [
url(r'^tag/create$', TagUpdateOrCreateView.as_view()),
url(r'^tag/detail$', TagUpdateOrCreateView.as_view()),
# 标签类型相关
url(r'^tag/tagtype/list$', TagTypeListView.as_view()),
url(r'^tag/tagtype/list/update$', TagTypeListView.as_view()),
url(r'^tag/tagtype/create$', TagTypeUpdateOrCreateView.as_view()),
url(r'^tag/tagtype/detail$', TagTypeUpdateOrCreateView.as_view()),
url(r'^face/star/create$', FaceStarEdit.as_view()),
url(r'^face/star/list$', StarListView.as_view()),
url(r'^face/star/list/update$', StarListView.as_view()),
......@@ -95,12 +101,13 @@ urlpatterns = [
search_urlpatterns = [
url(r'search/group$', GroupSearchView.as_view()),
url(r'search/country', CountrySearchView.as_view()),
url(r'search/user', UserSearchView.as_view()),
url(r'search/tag', TagSearchView.as_view()),
url(r'search/celebrity', CelebritySearchView.as_view()),
url(r'search/city', CitySearchView.as_view()),
url(r'search/topic', TopicSearchView.as_view()),
url(r'search/country$', CountrySearchView.as_view()),
url(r'search/user$', UserSearchView.as_view()),
url(r'search/tag$', TagSearchView.as_view()),
url(r'search/celebrity$', CelebritySearchView.as_view()),
url(r'search/city$', CitySearchView.as_view()),
url(r'search/topic$', TopicSearchView.as_view()),
url(r'search/tagtype$', TagTypeSearchView.as_view()),
]
common_urlpatterns = [
......
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "chenwei"
# Date: 2018/11/15
......@@ -63,3 +63,11 @@ export function topicSearch(name) {
params: { name }
})
}
export function tagTypeSearch(name) {
return request({
url: 'api/search/tagtype',
method: 'get',
params: { name }
})
}
import request from '@/utils/request'
export function fetchList(query) {
return request({
url: '/api/tag/tagtype/list',
method: 'get',
params: query
})
}
export function OffLineOrOnLine(data) {
return request({
url: '/api/tag/tagtype/list/update',
method: 'post',
data
})
}
export function CreateTagType(data) {
return request({
url: '/api/tag/tagtype/create',
method: 'post',
data
})
}
export function fetchTagTypeDetail(id) {
return request({
url: '/api/tag/tagtype/detail',
method: 'get',
params: { id }
})
}
......@@ -29,7 +29,27 @@ const TagRouter = {
name: 'EditTag',
meta: {title: '编辑标签', noCache: true},
hidden: true
}
},
{
path: 'tagtype/list',
component: () => import('@/views/tag_type/list'),
name: 'TagTypeList',
meta: {title: '标签类型列表', icon: 'list'}
},
{
path: 'tagtype/create',
component: () => import('@/views/tag_type/create'),
name: 'CreateTagType',
meta: {title: '创建标签类型', icon: 'edit'},
hidden: true
},
{
path: 'tagtype/edit/:id(\\d+)',
component: () => import('@/views/tag_type/edit'),
name: 'EditTagType',
meta: {title: '编辑标签类型', noCache: true},
hidden: true
},
]
}
......
......@@ -71,6 +71,18 @@
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label-width="75px" label="标签类型:" class="postInfo-container-item">
<el-select v-model="tagtypes" :remote-method="getRemoteTagTypeList" filterable remote multiple
value-key="id"
placeholder="搜索类型" style="width: 70%">
<el-option v-for="(item,index) in TagTypeListOptions" :key="item+index" :label="item"
:value="item"/>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-form-item style="margin-bottom: 40px;" label-width="75px" label="标签简介:" prop="desc">
<el-input :rows="1" v-model="postForm.description" type="textarea" class="article-textarea" autosize
placeholder="请输入内容"/>
......@@ -86,31 +98,9 @@
import MDinput from '@/components/MDinput'
import Sticky from '@/components/Sticky' // 粘性header组件
import {fetchTagDetail, CreateTag} from '@/api/tag'
import {tagSearch} from '@/api/remoteSearch'
import {isInArray, removeByvale} from "@/utils";
import {tagSearch, tagTypeSearch} from '@/api/remoteSearch'
import {isInArray} from "@/utils";
function Assembledata(target, source) {
var region_data = []
for (var i = 0; i < target.length; i++) {
if (isInArray(source, target[i]['name'])) {
region_data.push(target[i]['id'])
removeByvale(source, target[i]['name']);
}
}
region_data.push(...source)
return region_data.join(',')
}
function removeNull(parkingList) {
for (let i = 0; i < parkingList.length; i++) {
if (parkingList[i] == '' || parkingList[i] == null || typeof(parkingList[i]) == undefined) {
parkingList.splice(i, 1);
i = i - 1;
}
}
return parkingList
}
const defaultForm = {
status: 'draft',
......@@ -118,6 +108,7 @@
description: '',
up_tags: [],
down_tags: [],
tagtypes: [],
}
export default {
......@@ -146,16 +137,14 @@
postForm: Object.assign({}, defaultForm),
loading: false,
TagListOptions: [],
TagTypeListOptions: [],
up_tags: [],
down_tags: [],
tagtypes: [],
rules: {
name: [{validator: validateRequire, trigger: 'blur'}],
},
tempRoute: {},
temparray: {
'up_tags': [],
'down_tags': [],
}
}
},
computed: {
......@@ -184,6 +173,9 @@
for (let i = 0; i < rep.down_tags.length; i++) {
this.down_tags.push(rep.down_tags[i]['id'] + ':' + rep.down_tags[i]['name'])
}
for (let i = 0;i < rep.tagtypes.length; i++){
this.tagtypes.push(rep.tagtypes[i]['id'] + ':' + rep.tagtypes[i]['name'])
}
this.postForm = rep
}).catch(err => {
console.log(err)
......@@ -209,8 +201,8 @@
}
this.postForm.up_tags = JSON.stringify(this.up_tags)
this.postForm.down_tags = JSON.stringify(this.down_tags);
this.postForm.tagtypes = JSON.stringify(this.tagtypes);
CreateTag(this.postForm).then(response => {
console.log()
if (response.data.data.code == 500) {
this.$notify({
title: '失败',
......@@ -255,6 +247,12 @@
this.TagListOptions = response.data.data.data
})
},
getRemoteTagTypeList(query) {
tagTypeSearch(query).then(response => {
if (!response.data.data.data) return
this.TagTypeListOptions = response.data.data.data
})
}
}
}
</script>
......
......@@ -30,7 +30,7 @@
</el-table-column>
<el-table-column align="center" label="线">
<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>
......
<template>
<div class="createPost-container">
<el-form ref="postForm" :model="postForm" :rules="rules" class="form-container">
<sticky :class-name="'sub-navbar'">
<el-button v-loading="loading" style="margin-left: 10px;" type="success" @click="submitForm">保存
</el-button>
</sticky>
<div class="createPost-main-container">
<el-row>
<el-col :span="24">
<el-form-item style="margin-bottom: 40px;" prop="name">
<MDinput v-model="postForm.name" :maxlength="100" name="name" required>
标签类型名称
</MDinput>
</el-form-item>
</el-col>
</el-row>
<el-row>
</el-row>
</div>
</el-form>
</div>
</template>
<script>
import MDinput from '@/components/MDinput'
import Sticky from '@/components/Sticky' // 粘性header组件
import {fetchTagTypeDetail, CreateTagType} from '@/api/tagtype'
import {tagSearch} from '@/api/remoteSearch'
import {isInArray, removeByvale} from "@/utils";
const defaultForm = {
status: 'draft',
name: '',
}
export default {
name: 'TagTypeDetail',
components: {MDinput, Sticky},
props: {
isEdit: {
type: Boolean,
default: false
}
},
data() {
const validateRequire = (rule, value, callback) => {
value = value.trim()
if (value === '') {
this.$message({
message: rule.field + '为必传项',
type: 'error'
})
callback(new Error(rule.field + '为必传项'))
} else {
callback()
}
}
return {
postForm: Object.assign({}, defaultForm),
loading: false,
rules: {
name: [{validator: validateRequire, trigger: 'blur'}],
},
tempRoute: {},
}
},
created() {
if (this.isEdit) {
const id = this.$route.params && this.$route.params.id
this.fetchData(id)
} else {
this.postForm = Object.assign({}, defaultForm)
}
this.tempRoute = Object.assign({}, this.$route)
},
methods: {
fetchData(id) {
fetchTagTypeDetail(id).then(response => {
this.postForm = response.data.data.data
}).catch(err => {
console.log(err)
})
},
submitForm() {
this.$refs.postForm.validate(valid => {
if (valid) {
this.loading = true;
CreateTagType(this.postForm).then(response => {
if (response.data.data.code == 500) {
this.$notify({
title: '失败',
message: response.data.data.message,
type: 'error',
duration: 2000
})
this.loading = false
return false
}
this.$notify({
title: '成功',
message: response.data.data.message,
type: 'success',
duration: 2000
})
setTimeout(() => {
this.$router.push('/tag/tagtype/list')
}, 1000)
}).catch(err => {
this.$notify({
title: '失败',
message: '操作失败',
type: 'danger',
duration: 2000
})
});
this.postForm.status = 'published'
this.loading = false
} else {
console.log('error submit!!')
return false
}
})
},
}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/mixin.scss";
.createPost-container {
position: relative;
.createPost-main-container {
padding: 40px 45px 20px 50px;
.postInfo-container {
position: relative;
@include clearfix;
margin-bottom: 10px;
.postInfo-container-item {
float: left;
}
}
.editor-container {
min-height: 500px;
margin: 0 0 30px;
.editor-upload-btn-container {
text-align: right;
margin-right: 10px;
.editor-upload-btn {
display: inline-block;
}
}
}
}
.word-counter {
width: 40px;
position: absolute;
right: -10px;
top: 0px;
}
}
</style>
<template>
<tag-type-detail :is-edit="false"/>
</template>
<script>
import TagTypeDetail from './components/TagTypeDetail'
export default {
name: 'CreateTagType',
components: { TagTypeDetail }
}
</script>
<template>
<tag-type-detail :is-edit="true"/>
</template>
<script>
import TagTypeDetail from './components/TagTypeDetail'
export default {
name: 'EditTagType',
components: { TagTypeDetail }
}
</script>
<template>
<div class="app-container">
<div class="filter-container">
<el-input :placeholder="'搜素'" v-model="listQuery.filter.value" style="width: 150px;" class="filter-item" @keyup.enter.native="handleFilter"/>
<el-select v-model="listQuery.filter.key" :placeholder="'搜索字段'" clearable class="filter-item" style="width: 110px">
<el-option v-for="item in SearchTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
</el-select>
<el-select v-model="listQuery.filter.is_online" :placeholder="'上线'" clearable class="filter-item" style="width: 100px">
<el-option v-for="item in BooleanTypeOptions" :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>
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleOfflineOrOnline('online')">上线</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" align="center"></el-table-column>
<el-table-column align="center" label="标签类型ID" >
<template slot-scope="scope">
<router-link :to="'/tag/tagtype/edit/'+scope.row.id" class="link-type">
<span>{{ scope.row.id }}</span>
</router-link>
</template>
</el-table-column>
<el-table-column align="center" label="标签类型名称">
<template slot-scope="scope">
<span>{{ scope.row.name }}</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>
<pagination v-show="total>0" :total="total" :page.sync="listQuery.offset" :limit.sync="listQuery.limit" style="margin-left: 250px;" @pagination="getList" />
</div>
</template>
<script>
import { fetchList, OffLineOrOnLine } from '@/api/tagtype'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import waves from '@/directive/waves'
export default {
name: 'TagTypeList',
components: { Pagination },
filters: {
isOnlineFilter(status) {
const statusMap = {
1: 'success',
0: 'info',
}
return statusMap[status]
},
},
directives: { waves },
data() {
return {
list: null,
total: 0,
listLoading: true,
multipleSelection: [],
del_list: [],
listQuery: {
offset: 1,
limit: 10,
filter: {
value: '',
key: '',
is_online: '',
name: '',
type:'',
},
},
BooleanTypeOptions: [
{'key': 1, 'display_name': '是'},
{'key': 0, 'display_name': '否'}
],
SearchTypeOptions:[
{'key': 'id', 'display_name': 'ID'},
{'key': 'name', 'display_name': '类型名称'},
]
}
},
created() {
this.getList()
},
methods: {
getList() {
this.listLoading = true
fetchList(this.listQuery).then(response => {
this.list = response.data.data.data
this.total = response.data.data.total
this.listLoading = false
})
},
handleSelectionChange(val) {
this.multipleSelection = val;
},
handleSizeChange(val) {
this.listQuery.limit = val
this.getList()
},
handleCurrentChange(val) {
this.listQuery.offset = val
this.getList()
},
handleOfflineOrOnline(val){
const length = this.multipleSelection.length;
let str = '';
var update = ''
this.del_list = this.del_list.concat(this.multipleSelection);
for (let i = 0; i < length; i++) {
if (val === 'offline'){
this.multipleSelection[i].is_online = 0
update = 0;
}else{
this.multipleSelection[i].is_online = 1
update = 1;
}
str += this.multipleSelection[i].id + ' ';
}
OffLineOrOnLine({update:update, ids:str}).then(response => {
this.multipleSelection = [];
this.$message.success(response.data.data.message);
})
},
handleFilter() {
this.listQuery.offset = 1
if (this.listQuery.filter.key == 'id' && !/^\d+$/.test(this.listQuery.filter.value)){
this.$message.error("搜索条件不合法, 重新输入")
return false;
}
this.getList()
},
handleCreate() {
this.$router.push('/tag/tagtype/create')
}
}
}
</script>
<style scoped>
.edit-input {
padding-right: 100px;
}
.cancel-btn {
position: absolute;
right: 15px;
top: 10px;
}
</style>
......@@ -10,7 +10,11 @@
<el-row :gutter="20">
<el-card class="box-card">
<div slot="header" class="clearfix">
<span>帖子相关</span>
<div style="float: left; text-align: center;">
帖子相关
</div>
</div>
<el-row>
<el-col :span="24">
......@@ -103,6 +107,9 @@
</div>
</el-col>
</el-row>
<el-form-item label-width="75px" label="人工减分:" class="postInfo-container-item" style="margin-bottom: 20px">
<el-input v-model="postForm.drop_score" type="number" style="width: 80%"/>
</el-form-item>
<el-form-item style="margin-bottom: 20px" label-width="75px" label="是否在线:">
<el-radio-group v-model="postForm.is_online">
<el-radio :label="1"></el-radio>
......@@ -306,6 +313,7 @@
star: '',
is_puppet: '',
is_online: 0,
drop_score: 0,
}
export default {
......
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