Commit a7b59391 authored by Davve's avatar Davve

完成明星创建逻辑

parent 208b2164
...@@ -13,7 +13,6 @@ class GroupListView(APIView): ...@@ -13,7 +13,6 @@ class GroupListView(APIView):
filters = self.handle_filter(request.GET.get('filter', "")) filters = self.handle_filter(request.GET.get('filter', ""))
try: try:
data = self.rpc['venus/community/group/list'](filters=filters, offset=offset, count=count).unwrap() data = self.rpc['venus/community/group/list'](filters=filters, offset=offset, count=count).unwrap()
print(data, '----------------')
except Exception as e: except Exception as e:
raise e raise e
return data return data
...@@ -34,4 +33,30 @@ class GroupListView(APIView): ...@@ -34,4 +33,30 @@ class GroupListView(APIView):
raise e raise e
return { return {
"message": "更新成功" "message": "更新成功"
} }
\ No newline at end of file
class GroupUpdateOrCreate(APIView):
def get(self, request):
id = request.GET.get('id')
try:
data = self.rpc['venus/community/group/detail'](id=id).unwrap()
except Exception as e:
data = [{
'id': 1,
'name': '我是一个小组名称',
'description': '小组简介简介',
'user_nums': 22,
'topic_nums': 32,
'user': {
'id': 22,
'name': '真好',
}
},]
return {
'total': 20,
'data': data
}
def post(self, request):
pass
\ No newline at end of file
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# __author__ = "chenwei" # __author__ = "chenwei"
# Date: 2018/11/15 # Date: 2018/11/15
import json
from utils.base import APIView from utils.base import APIView
...@@ -15,4 +16,32 @@ class StarListView(APIView): ...@@ -15,4 +16,32 @@ class StarListView(APIView):
data = self.rpc['venus/community/star/get'](offset=page, limit=limit, filters=filter).unwrap() data = self.rpc['venus/community/star/get'](offset=page, limit=limit, filters=filter).unwrap()
except Exception as e: except Exception as e:
raise e raise e
return data return data
\ No newline at end of file
class StarUpdateOrCreate(APIView):
def get(self, request):
id = request.GET.get('id')
try:
data = self.rpc['venus/community/star/detail'](id=id).unwrap()
except Exception as e:
raise e
return {'data': data}
def post(self, request):
data = {
'gender': request.POST.get('gender'),
'region': request.POST.get('region'),
'is_online': request.POST.get('is_online'),
'description': request.POST.get('description'),
'avatar': request.POST.get('avatar')[:-2],
'group_ids': list(set(json.loads(request.POST.get('group_ids', [])))),
}
try:
self.rpc['venus/community/star/create'](data=data).unwrap()
except Exception as e:
raise e
return {
'message': '更新成功'
}
\ No newline at end of file
...@@ -34,12 +34,15 @@ urlpatterns = [ ...@@ -34,12 +34,15 @@ urlpatterns = [
# group相关 # group相关
url(r'group/list$', GroupListView.as_view()), url(r'group/list$', GroupListView.as_view()),
url(r'group/update$', GroupListView.as_view()), url(r'group/update$', GroupListView.as_view()),
url(r'group/detail', GroupUpdateOrCreate.as_view()),
# topic相关 # topic相关
url(r'topic/list$', TopicListView.as_view()), url(r'topic/list$', TopicListView.as_view()),
# star相关 # star相关
url(r'star/list$', StarListView.as_view()), url(r'star/list$', StarListView.as_view()),
url(r'star/create', StarUpdateOrCreate.as_view()),
url(r'star/detail', StarUpdateOrCreate.as_view()),
# push相关 # push相关
url(r'push/list$', PushListView.as_view()), url(r'push/list$', PushListView.as_view()),
......
...@@ -15,3 +15,11 @@ export function OffLineOrOnLine(data) { ...@@ -15,3 +15,11 @@ export function OffLineOrOnLine(data) {
data data
}) })
} }
export function GroupDetail(id) {
return request({
url: '/api/group/detail',
method: 'get',
params: { id }
})
}
...@@ -8,6 +8,21 @@ export function fetchList(query) { ...@@ -8,6 +8,21 @@ export function fetchList(query) {
}) })
} }
export function starCreate(data) {
return request({
url: '/api/star/create',
method: 'post',
data
})
}
export function starDetail(id) {
return request({
url: '/api/star/detail',
method: 'get',
params: { id }
})
}
export function OffLineOrOnLine(data) { export function OffLineOrOnLine(data) {
return request({ return request({
...@@ -16,3 +31,11 @@ export function OffLineOrOnLine(data) { ...@@ -16,3 +31,11 @@ export function OffLineOrOnLine(data) {
data data
}) })
} }
export function fetchStarRelatedGroup(id) {
return request({
url: '/api/star/star_related_group_info',
method: 'get',
params: { id }
})
}
...@@ -241,7 +241,6 @@ ...@@ -241,7 +241,6 @@
this.postForm.region = Assembledata(this.temparray['region'], this.postForm.region); this.postForm.region = Assembledata(this.temparray['region'], this.postForm.region);
this.postForm.pick_group = Assembledata(this.temparray['pick_group'], this.postForm.pick_group); this.postForm.pick_group = Assembledata(this.temparray['pick_group'], this.postForm.pick_group);
}else{ }else{
console.log(this.postForm.region)
this.postForm.region = this.postForm.region.join(',') this.postForm.region = this.postForm.region.join(',')
this.postForm.pick_group = this.postForm.pick_group.join(',') this.postForm.pick_group = this.postForm.pick_group.join(',')
} }
......
...@@ -72,11 +72,10 @@ ...@@ -72,11 +72,10 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label-width="45px" label="地区:" style="margin-left: 10px"> <el-form-item label-width="45px" label="地区:" style="margin-left: 10px">
<el-select v-model="postForm.region" :remote-method="getRemoteGroupList" filterable remote <el-select v-model="postForm.region" :remote-method="getRemoteRegionList" filterable remote
multiple value-key="id" value-key="id"
placeholder="搜索地区" style="width: 220px"> placeholder="搜索地区" style="width: 220px">
<el-option v-for="(item,index) in regionListOptions" :key="item+index" :label="item.name" <el-option v-for="(item,index) in regionListOptions" :key="item+index" :label="item.name" :value="item.id"/>
:value="item.id"/>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item style="margin-bottom: 20px;margin-left: 10px" label-width="45px" label="下线:"> <el-form-item style="margin-bottom: 20px;margin-left: 10px" label-width="45px" label="下线:">
...@@ -94,8 +93,8 @@ ...@@ -94,8 +93,8 @@
<div style="margin-bottom: 20px;margin-left: 10px"> <div style="margin-bottom: 20px;margin-left: 10px">
<el-form-item style="margin-bottom: 40px;" label-width="75px" label="明星头像:" prop="avatar"> <el-form-item style="margin-bottom: 40px;" label-width="75px" label="明星头像:" prop="avatar">
<span v-model="type"></span> <span v-model="uploadType"></span>
<Upload v-model="postForm.avatar" :type="type"/> <Upload v-model="postForm.avatar" :uploadType="uploadType"/>
</el-form-item> </el-form-item>
</div> </div>
...@@ -108,15 +107,17 @@ ...@@ -108,15 +107,17 @@
</div> </div>
<div style="margin-bottom:50px;"> <div style="margin-bottom:50px;">
<div class="filter-container"> <div class="filter-container">
<el-input :placeholder="'添加小组'" v-model="listQuery.filter.value" style="width: 180px;" <el-select v-model="temp_group_ids" :remote-method="getRemoteGroupList" filterable remote
class="filter-item" value-key="id"
@keyup.enter.native="appendUser"/> placeholder="小组" style="width: 220px">
<el-option v-for="(item,index) in groupListOptions" :key="item+index" :label="item.id + ':' + item.name" :value="item.id"/>
</el-select>
<el-button v-waves class="filter-item" type="primary" icon="el-icon-edit" @click="appendUser">添加 <el-button v-waves class="filter-item" type="primary" icon="el-icon-edit" @click="appendUser">添加
</el-button> </el-button>
<el-button v-waves class="filter-item" type="primary" icon="el-icon-delete" @click="delUser">移除 <el-button v-waves class="filter-item" type="primary" icon="el-icon-delete" @click="delUser">移除
</el-button> </el-button>
</div> </div>
<el-table :data="list" border fit highlight-current-row style="width: 100%" <el-table :data="data" border fit highlight-current-row style="width: 100%"
ref="multipleTable" @selection-change="handleSelectionChange"> ref="multipleTable" @selection-change="handleSelectionChange">
<el-table-column type="selection" align="center"></el-table-column> <el-table-column type="selection" align="center"></el-table-column>
<el-table-column align="center" label="小组ID "> <el-table-column align="center" label="小组ID ">
...@@ -128,27 +129,27 @@ ...@@ -128,27 +129,27 @@
</el-table-column> </el-table-column>
<el-table-column align="center" label="小组名称"> <el-table-column align="center" label="小组名称">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.row.username }}</span> <span>{{ scope.row.name }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="小组简介"> <el-table-column align="center" label="小组简介">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.phone }}</span> <span>{{ scope.row.description }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="用户数"> <el-table-column align="center" label="用户数">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.row.topic_nums }}</span> <span>{{ scope.row.user_nums }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="帖子数"> <el-table-column align="center" label="帖子数">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.row.user_identity }}</span> <span>{{ scope.row.topic_nums }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="组长"> <el-table-column align="center" label="组长">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.row.internal_identity }}</span> <span>{{ scope.row.user.name }}</span>
</template> </template>
</el-table-column> </el-table-column>
...@@ -165,34 +166,29 @@ ...@@ -165,34 +166,29 @@
</template> </template>
<script> <script>
import Tinymce from '@/components/Tinymce'
import Upload from '@/components/Upload/singleImage3' import Upload from '@/components/Upload/singleImage3'
import MDinput from '@/components/MDinput' import MDinput from '@/components/MDinput'
import Sticky from '@/components/Sticky' // 粘性header组件 import Sticky from '@/components/Sticky' // 粘性header组件
import waves from '@/directive/waves' import waves from '@/directive/waves'
import Pagination from '@/components/Pagination' import Pagination from '@/components/Pagination'
import {validateURL} from '@/utils/validate' import {starCreate, starDetail, fetchStarRelatedGroup} from '@/api/star'
import {fetchArticle} from '@/api/article' import { GroupDetail } from '@/api/group'
import {regionSearch} from '@/api/remoteSearch' import {regionSearch, groupSearch} from '@/api/remoteSearch'
const defaultForm = { const defaultForm = {
status: 'draft', status: 'draft',
title: '', // 文章题目 name: '',
content: '', // 文章内容 gender: '',
content_short: '', // 文章摘要 region: '',
source_uri: '', // 文章外链 is_online: undefined,
image_uri: '', // 文章图片 description: '',
display_time: undefined, // 前台展示时间 avatar: '',
id: undefined, group_ids: [],
platforms: ['a-platform'],
comment_disabled: false,
importance: 0,
avatar: ''
} }
export default { export default {
name: 'ArticleDetail', name: 'StarDetail',
components: {Tinymce, MDinput, Upload, Sticky, Pagination}, components: {MDinput, Upload, Sticky, Pagination},
directives: {waves}, directives: {waves},
props: { props: {
isEdit: { isEdit: {
...@@ -212,30 +208,13 @@ ...@@ -212,30 +208,13 @@
callback() callback()
} }
} }
const validateSourceUri = (rule, value, callback) => {
if (value) {
if (validateURL(value)) {
callback()
} else {
this.$message({
message: '外链url填写不正确',
type: 'error'
})
callback(new Error('外链url填写不正确'))
}
} else {
callback()
}
}
return { return {
postForm: Object.assign({}, defaultForm), postForm: Object.assign({}, defaultForm),
loading: false, loading: false,
userListOptions: [], groupListOptions: [],
temp_group_ids: [],
rules: { rules: {
image_uri: [{validator: validateRequire}], content: [{validator: validateRequire, trigger: 'blur'}]
title: [{validator: validateRequire}],
content: [{validator: validateRequire}],
source_uri: [{validator: validateSourceUri, trigger: 'blur'}]
}, },
GenderTypeOptions: [ GenderTypeOptions: [
{'key': 0, 'display_name': '男'}, {'key': 0, 'display_name': '男'},
...@@ -243,42 +222,50 @@ ...@@ -243,42 +222,50 @@
], ],
tempRoute: {}, tempRoute: {},
regionListOptions: [], regionListOptions: [],
type: 99, uploadType: 99,
list: null, list: [],
total: 1, tableData: [],
total: 0,
listLoading: true, listLoading: true,
multipleSelection: [], multipleSelection: [],
del_list: [], del_list: [],
listQuery: { listQuery: {
page: 0, page: 0,
limit: 10, limit: 10,
filter: {
value: '',
key: '',
},
}, },
} }
}, },
computed: { computed: {
contentShortLength() { contentShortLength() {
return this.postForm.content_short.length return this.postForm.description.length
}, },
lang() { lang() {
return this.$store.getters.language return this.$store.getters.language
},
data() {
return this.tableData.filter((d) => {
let is_del = false;
for (let i = 0;i < this.del_list.length; i++){
if (d.id == this.del_list[i].id){
is_del = true;
break
}
}
if (!is_del){
return d
}
})
} }
}, },
created() { created() {
if (this.isEdit) { if (this.isEdit) {
const id = this.$route.params && this.$route.params.id const id = this.$route.params && this.$route.params.id
this.fetchData(id) this.fetchData(id)
this.getList() this.getList(id)
} else { } else {
this.postForm = Object.assign({}, defaultForm) this.postForm = Object.assign({}, defaultForm)
} }
// Why need to make a copy of this.$route here?
// Because if you enter this page and quickly switch tag, may be in the execution of the setTagsViewTitle function, this.$route is no longer pointing to the current page
// https://github.com/PanJiaChen/vue-element-admin/issues/1221
this.tempRoute = Object.assign({}, this.$route) this.tempRoute = Object.assign({}, this.$route)
}, },
methods: { methods: {
...@@ -289,64 +276,69 @@ ...@@ -289,64 +276,69 @@
this.postForm.title += ` Article Id:${this.postForm.id}` this.postForm.title += ` Article Id:${this.postForm.id}`
this.postForm.content_short += ` Article Id:${this.postForm.id}` this.postForm.content_short += ` Article Id:${this.postForm.id}`
// Set tagsview title
this.setTagsViewTitle()
}).catch(err => { }).catch(err => {
console.log(err) console.log(err)
}) })
}, },
setTagsViewTitle() {
const title = this.lang === 'zh' ? '编辑文章' : 'Edit Article'
const route = Object.assign({}, this.tempRoute, {title: `${title}-${this.postForm.id}`})
this.$store.dispatch('updateVisitedView', route)
},
submitForm() { submitForm() {
this.postForm.display_time = parseInt(this.display_time / 1000)
console.log(this.postForm)
this.$refs.postForm.validate(valid => { this.$refs.postForm.validate(valid => {
if (valid) { if (valid) {
this.loading = true this.loading = true
this.$notify({ this.postForm.group_ids = JSON.stringify(this.postForm.group_ids)
title: '成功', starCreate(this.postForm).then(response => {
message: '发布文章成功', this.$notify({
type: 'success', title: '成功',
duration: 2000 message: response.data.data.message,
}) type: 'success',
duration: 2000
})
setTimeout(() => {
this.$router.push('/star/list')
}, 1000)
}).catch(err => {
this.$notify({
title: '失败',
message: '操作失败',
type: 'danger',
duration: 2000
})
});
this.postForm.status = 'published' this.postForm.status = 'published'
this.loading = false this.loading = false
} else { } else {
console.log('error submit!!') console.log('error submit!!')
return false return false
} }
}) })
}, },
draftForm() { getRemoteGroupList(query) {
if (this.postForm.content.length === 0 || this.postForm.title.length === 0) { groupSearch(query).then(response => {
this.$message({ if (!response.data.data.data) return
message: '请填写必要的标题和内容', this.groupListOptions = response.data.data.data
type: 'warning'
})
return
}
this.$message({
message: '保存成功',
type: 'success',
showClose: true,
duration: 1000
}) })
this.postForm.status = 'draft'
}, },
getRemoteGroupList(query) { getRemoteRegionList(query) {
regionSearch(query).then(response => { regionSearch(query).then(response => {
if (!response.data.items) return if (!response.data.data.data) return
this.userListOptions = response.data.items.map(v => v.name) this.regionListOptions = response.data.data.data
}) })
}, },
appendUser() { appendUser() {
GroupDetail(this.temp_group_ids).then(response => {
if (!response.data.data.data) return
this.tableData.push(...response.data.data.data)
this.total = response.data.data.total
})
this.postForm.group_ids.push(this.temp_group_ids)
this.temp_group_ids = ''
}, },
delUser() { delUser() {
const lenth = this.multipleSelection.length;
this.del_list = this.del_list.concat(this.multipleSelection);
console.log(this.del_list)
}, },
handleSelectionChange(val) { handleSelectionChange(val) {
this.multipleSelection = val; this.multipleSelection = val;
...@@ -359,9 +351,9 @@ ...@@ -359,9 +351,9 @@
this.listQuery.page = val this.listQuery.page = val
this.getList() this.getList()
}, },
getList() { getList(id) {
this.listLoading = true this.listLoading = true
fetchList(this.listQuery).then(response => { fetchStarRelatedGroup(id).then(response => {
this.list = [] this.list = []
this.total = 100 this.total = 100
this.listLoading = false this.listLoading = false
......
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