Commit a7b59391 authored by Davve's avatar Davve

完成明星创建逻辑

parent 208b2164
......@@ -13,7 +13,6 @@ class GroupListView(APIView):
filters = self.handle_filter(request.GET.get('filter', ""))
try:
data = self.rpc['venus/community/group/list'](filters=filters, offset=offset, count=count).unwrap()
print(data, '----------------')
except Exception as e:
raise e
return data
......@@ -35,3 +34,29 @@ class GroupListView(APIView):
return {
"message": "更新成功"
}
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 @@
# __author__ = "chenwei"
# Date: 2018/11/15
import json
from utils.base import APIView
......@@ -16,3 +17,31 @@ class StarListView(APIView):
except Exception as e:
raise e
return data
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 = [
# group相关
url(r'group/list$', GroupListView.as_view()),
url(r'group/update$', GroupListView.as_view()),
url(r'group/detail', GroupUpdateOrCreate.as_view()),
# topic相关
url(r'topic/list$', TopicListView.as_view()),
# star相关
url(r'star/list$', StarListView.as_view()),
url(r'star/create', StarUpdateOrCreate.as_view()),
url(r'star/detail', StarUpdateOrCreate.as_view()),
# push相关
url(r'push/list$', PushListView.as_view()),
......
......@@ -15,3 +15,11 @@ export function OffLineOrOnLine(data) {
data
})
}
export function GroupDetail(id) {
return request({
url: '/api/group/detail',
method: 'get',
params: { id }
})
}
......@@ -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) {
return request({
......@@ -16,3 +31,11 @@ export function OffLineOrOnLine(data) {
data
})
}
export function fetchStarRelatedGroup(id) {
return request({
url: '/api/star/star_related_group_info',
method: 'get',
params: { id }
})
}
......@@ -241,7 +241,6 @@
this.postForm.region = Assembledata(this.temparray['region'], this.postForm.region);
this.postForm.pick_group = Assembledata(this.temparray['pick_group'], this.postForm.pick_group);
}else{
console.log(this.postForm.region)
this.postForm.region = this.postForm.region.join(',')
this.postForm.pick_group = this.postForm.pick_group.join(',')
}
......
......@@ -72,11 +72,10 @@
</el-select>
</el-form-item>
<el-form-item label-width="45px" label="地区:" style="margin-left: 10px">
<el-select v-model="postForm.region" :remote-method="getRemoteGroupList" filterable remote
multiple value-key="id"
<el-select v-model="postForm.region" :remote-method="getRemoteRegionList" filterable remote
value-key="id"
placeholder="搜索地区" style="width: 220px">
<el-option v-for="(item,index) in regionListOptions" :key="item+index" :label="item.name"
:value="item.id"/>
<el-option v-for="(item,index) in regionListOptions" :key="item+index" :label="item.name" :value="item.id"/>
</el-select>
</el-form-item>
<el-form-item style="margin-bottom: 20px;margin-left: 10px" label-width="45px" label="下线:">
......@@ -94,8 +93,8 @@
<div style="margin-bottom: 20px;margin-left: 10px">
<el-form-item style="margin-bottom: 40px;" label-width="75px" label="明星头像:" prop="avatar">
<span v-model="type"></span>
<Upload v-model="postForm.avatar" :type="type"/>
<span v-model="uploadType"></span>
<Upload v-model="postForm.avatar" :uploadType="uploadType"/>
</el-form-item>
</div>
......@@ -108,15 +107,17 @@
</div>
<div style="margin-bottom:50px;">
<div class="filter-container">
<el-input :placeholder="'添加小组'" v-model="listQuery.filter.value" style="width: 180px;"
class="filter-item"
@keyup.enter.native="appendUser"/>
<el-select v-model="temp_group_ids" :remote-method="getRemoteGroupList" filterable remote
value-key="id"
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>
<el-button v-waves class="filter-item" type="primary" icon="el-icon-delete" @click="delUser">移除
</el-button>
</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">
<el-table-column type="selection" align="center"></el-table-column>
<el-table-column align="center" label="小组ID ">
......@@ -128,27 +129,27 @@
</el-table-column>
<el-table-column align="center" label="小组名称">
<template slot-scope="scope">
<span>{{ scope.row.username }}</span>
<span>{{ scope.row.name }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="小组简介">
<template slot-scope="scope">
<span>{{ scope.phone }}</span>
<span>{{ scope.row.description }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="用户数">
<template slot-scope="scope">
<span>{{ scope.row.topic_nums }}</span>
<span>{{ scope.row.user_nums }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="帖子数">
<template slot-scope="scope">
<span>{{ scope.row.user_identity }}</span>
<span>{{ scope.row.topic_nums }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="组长">
<template slot-scope="scope">
<span>{{ scope.row.internal_identity }}</span>
<span>{{ scope.row.user.name }}</span>
</template>
</el-table-column>
......@@ -165,34 +166,29 @@
</template>
<script>
import Tinymce from '@/components/Tinymce'
import Upload from '@/components/Upload/singleImage3'
import MDinput from '@/components/MDinput'
import Sticky from '@/components/Sticky' // 粘性header组件
import waves from '@/directive/waves'
import Pagination from '@/components/Pagination'
import {validateURL} from '@/utils/validate'
import {fetchArticle} from '@/api/article'
import {regionSearch} from '@/api/remoteSearch'
import {starCreate, starDetail, fetchStarRelatedGroup} from '@/api/star'
import { GroupDetail } from '@/api/group'
import {regionSearch, groupSearch} from '@/api/remoteSearch'
const defaultForm = {
status: 'draft',
title: '', // 文章题目
content: '', // 文章内容
content_short: '', // 文章摘要
source_uri: '', // 文章外链
image_uri: '', // 文章图片
display_time: undefined, // 前台展示时间
id: undefined,
platforms: ['a-platform'],
comment_disabled: false,
importance: 0,
avatar: ''
name: '',
gender: '',
region: '',
is_online: undefined,
description: '',
avatar: '',
group_ids: [],
}
export default {
name: 'ArticleDetail',
components: {Tinymce, MDinput, Upload, Sticky, Pagination},
name: 'StarDetail',
components: {MDinput, Upload, Sticky, Pagination},
directives: {waves},
props: {
isEdit: {
......@@ -212,30 +208,13 @@
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 {
postForm: Object.assign({}, defaultForm),
loading: false,
userListOptions: [],
groupListOptions: [],
temp_group_ids: [],
rules: {
image_uri: [{validator: validateRequire}],
title: [{validator: validateRequire}],
content: [{validator: validateRequire}],
source_uri: [{validator: validateSourceUri, trigger: 'blur'}]
content: [{validator: validateRequire, trigger: 'blur'}]
},
GenderTypeOptions: [
{'key': 0, 'display_name': '男'},
......@@ -243,42 +222,50 @@
],
tempRoute: {},
regionListOptions: [],
type: 99,
list: null,
total: 1,
uploadType: 99,
list: [],
tableData: [],
total: 0,
listLoading: true,
multipleSelection: [],
del_list: [],
listQuery: {
page: 0,
limit: 10,
filter: {
value: '',
key: '',
},
},
}
},
computed: {
contentShortLength() {
return this.postForm.content_short.length
return this.postForm.description.length
},
lang() {
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() {
if (this.isEdit) {
const id = this.$route.params && this.$route.params.id
this.fetchData(id)
this.getList()
this.getList(id)
} else {
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)
},
methods: {
......@@ -289,64 +276,69 @@
this.postForm.title += ` Article Id:${this.postForm.id}`
this.postForm.content_short += ` Article Id:${this.postForm.id}`
// Set tagsview title
this.setTagsViewTitle()
}).catch(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() {
this.postForm.display_time = parseInt(this.display_time / 1000)
console.log(this.postForm)
this.$refs.postForm.validate(valid => {
if (valid) {
this.loading = true
this.postForm.group_ids = JSON.stringify(this.postForm.group_ids)
starCreate(this.postForm).then(response => {
this.$notify({
title: '成功',
message: '发布文章成功',
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.loading = false
} else {
console.log('error submit!!')
return false
}
})
},
draftForm() {
if (this.postForm.content.length === 0 || this.postForm.title.length === 0) {
this.$message({
message: '请填写必要的标题和内容',
type: 'warning'
})
return
}
this.$message({
message: '保存成功',
type: 'success',
showClose: true,
duration: 1000
getRemoteGroupList(query) {
groupSearch(query).then(response => {
if (!response.data.data.data) return
this.groupListOptions = response.data.data.data
})
this.postForm.status = 'draft'
},
getRemoteGroupList(query) {
getRemoteRegionList(query) {
regionSearch(query).then(response => {
if (!response.data.items) return
this.userListOptions = response.data.items.map(v => v.name)
if (!response.data.data.data) return
this.regionListOptions = response.data.data.data
})
},
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() {
const lenth = this.multipleSelection.length;
this.del_list = this.del_list.concat(this.multipleSelection);
console.log(this.del_list)
},
handleSelectionChange(val) {
this.multipleSelection = val;
......@@ -359,9 +351,9 @@
this.listQuery.page = val
this.getList()
},
getList() {
getList(id) {
this.listLoading = true
fetchList(this.listQuery).then(response => {
fetchStarRelatedGroup(id).then(response => {
this.list = []
this.total = 100
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