Commit 39257d20 authored by Davve's avatar Davve

修改问题

parent 10763992
......@@ -78,6 +78,10 @@ class LoginView(APIView):
data.update({
'avatar': settings.AVATAR
})
if data['is_staff']:
data.update({'roles': ['staff']})
else:
data.update({'roles': ['anonymous']})
except Exception as e:
error_logger.error(u'获取用户信息失败,%s' % (id, e))
raise
......@@ -94,7 +98,7 @@ class LoginView(APIView):
try:
data = self.rpc['venus/sun/account/login'](username=username, password=password).unwrap()
if data['success'] or all([username == settings.USERNAME, password == settings.PASSWORD]):
data = {
ret = {
'id': data['id'],
'avatar': settings.AVATAR,
'name': data['username'],
......@@ -102,19 +106,23 @@ class LoginView(APIView):
'success': 1,
}
else:
data = {
ret = {
'id': data['id'],
'avatar': settings.AVATAR,
'name': '',
'session_key': data['session'],
'success': 0,
'message': data['message']
'message': data['message'],
}
except Exception as e:
error_logger.error(u'登陆失败%s', e)
raise
if data['is_staff']:
ret.update({'roles': ['staff']})
else:
ret.update({'roles': ['anonymous']})
return {
'data': data
'data': ret
}
......
......@@ -52,14 +52,17 @@ class GroupUpdateOrCreate(APIView):
try:
data = self.rpc['venus/sun/group/get'](id=id).unwrap()
except Exception as e:
error_logger.error(u'获取%d用户信息失败%s'%(id, e))
error_logger.error(u'获取%s用户信息失败%s'%(id, e))
raise
return data
def post(self, request):
id = request.POST.get('id')
star_ids = list(map(lambda x: x.split(":")[0], json.loads(request.POST.get('star', '[]'))))
group_user_ids = list(map(lambda x: x.split(":")[0], json.loads(request.POST.get('group_users', '[]'))))
try:
group_user_ids = list(map(lambda x: x.split(":")[0], json.loads(request.POST.get('group_users', '[]'))))
except:
group_user_ids = json.loads(request.POST.get('group_users', '[]'))
data = {
'name': request.POST.get('name', ''),
'description': request.POST.get('description', ''),
......@@ -73,7 +76,7 @@ class GroupUpdateOrCreate(APIView):
try:
self.rpc['venus/sun/group/edit'](id=id, data=data).unwrap()
except Exception as e:
error_logger.error(u'编辑%d用户信息失败%s' % (id, e))
error_logger.error(u'编辑%s用户信息失败%s' % (id, e))
raise
return {
'message': '更新成功'
......
......@@ -37,11 +37,14 @@ class PushUpdateOrCreateView(APIView):
push_time = analysis_time(request.POST.get('push_time', 0))
group_topic_id = request.POST.get('group_topic_id', '')
full_url = request.POST.get('url', '') + group_topic_id
icon = request.POST.get('icon', '')
if icon.endswith('-w'):
icon = request.POST.get('icon', '')[:-2]
data = {
'url': full_url,
'push_time': push_time,
'icon': request.POST.get('icon', '')[:-2],
'icon': icon,
'content': request.POST.get('content', ''),
'title': request.POST.get('title', ''),
'creator_id': creator_id
......
......@@ -41,7 +41,6 @@ class TopicUpdateOrCreateView(APIView):
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', []))))
tag_ids = list(map(lambda x: x.split(':')[0], json.loads(request.POST.get('tags', '[]'))))
......@@ -73,7 +72,7 @@ class ReplyUpdateOrCreateView(APIView):
offset = int(request.GET.get('page', 0))
limit = int(request.GET.get('limit', 10))
filter = self.handle_filter(request.GET.get('filter', ""))
filter.update({'topic_id': id, 'is_online': 1})
filter.update({'topic_id': id})
try:
data = self.rpc['venus/sun/topic/reply/list'](offset=(offset-1) * limit, limit=limit, filters=filter).unwrap()
except Exception as e:
......@@ -95,6 +94,7 @@ class ReplyUpdateOrCreateView(APIView):
class ReplyCreate(APIView):
def post(self, request):
request.POST.get('be_replied_id', None)
data = {
'user_id': request.POST.get('user_id').split(':')[0],
'replied_id': request.POST.get("replied_id", None),
......
......@@ -32,7 +32,7 @@ class UserUpdateOrCreate(APIView):
try:
data = self.rpc['venus/sun/user/get'](id=id).unwrap()
except Exception as e:
error_logger.error(u'获取%d用户详情失败%s'%(id, e))
error_logger.error(u'获取%s用户详情失败%s'%(id, e))
raise
return data
......@@ -59,7 +59,7 @@ class UserUpdateOrCreate(APIView):
try:
self.rpc['venus/sun/user/edit'](id=id, data=data).unwrap()
except Exception as e:
error_logger.error(u'创建/编辑%d用户详情失败%s' % (id, e))
error_logger.error(u'创建/编辑%s用户详情失败%s' % (id, e))
raise
return {
'message': '更新成功'
......
......@@ -54,7 +54,7 @@ def analysis_time(time):
:return:
"""
try:
target_time = unix_time_to_datetime(int(time) / 1000)
target_time = unix_time_to_datetime(int(float(time)) / 1000)
except ValueError:
target_time = utc_to_datetime(time[:-5] + 'Z')
......
......@@ -26,7 +26,7 @@ router.beforeEach((to, from, next) => {
} else {
if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息
store.dispatch('GetUserInfo').then(res => { // 拉取user_info
const roles = res.data.roles // note: roles must be a array! such as: ['editor','develop']
const roles = res.data.data.data.roles // note: roles must be a array! such as: ['editor','develop']
store.dispatch('GenerateRoutes', { roles }).then(() => { // 根据roles权限生成可访问的路由表
router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
......
......@@ -9,14 +9,16 @@ const AccountRouter = {
name: 'Account',
meta: {
title: '账号管理',
icon: 'component'
icon: 'component',
roles: ['staff']
},
children: [
{
path: 'list',
component: () => import('@/views/account/list'),
name: 'AccountList',
meta: {title: '账户列表', icon: 'list'}
meta: {
title: '账户列表', icon: 'list'}
},
{
path: 'create',
......
......@@ -9,7 +9,8 @@ const GroupRouter = {
name: 'Group',
meta: {
title: '小组管理',
icon: 'component'
icon: 'component',
roles: ['staff']
},
children: [
{
......
......@@ -9,7 +9,8 @@ const PickRouter = {
name: 'Pick',
meta: {
title: 'Pick管理',
icon: 'component'
icon: 'component',
roles: ['staff']
},
children: [
{
......
......@@ -9,7 +9,8 @@ const PushRouter = {
name: 'Push',
meta: {
title: 'Push管理',
icon: 'component'
icon: 'component',
roles: ['staff']
},
children: [
{
......
......@@ -9,7 +9,8 @@ const StarRouter = {
name: 'Star',
meta: {
title: '明星管理',
icon: 'component'
icon: 'component',
roles: ['staff']
},
children: [
{
......
......@@ -7,7 +7,8 @@ const TagRouter = {
name: 'Tag',
meta: {
title: '标签管理',
icon: 'component'
icon: 'component',
roles: ['staff', 'anonymous']
},
children: [
{
......
......@@ -9,7 +9,8 @@ const TopicRouter = {
name: 'Topic',
meta: {
title: '帖子管理',
icon: 'component'
icon: 'component',
roles: ['staff', 'anonymous']
},
children: [
{
......
......@@ -9,7 +9,8 @@ const GroupRouter = {
name: 'User',
meta: {
title: '用户管理',
icon: 'component'
icon: 'component',
roles: ['staff', 'anonymous']
},
children: [
{
......
......@@ -48,14 +48,16 @@ const permission = {
actions: {
GenerateRoutes({ commit }, data) {
return new Promise(resolve => {
// const { roles } = data
// const accessedRouters = asyncRouterMap
// if (roles.includes('admin')) {
// accessedRouters = asyncRouterMap
// } else {
// accessedRouters = filterAsyncRouter(asyncRouterMap, roles)
// }
commit('SET_ROUTERS', asyncRouterMap)
const { roles } = data
let accessedRouters
if (roles.includes('staff')) {
accessedRouters = asyncRouterMap
console.log(accessedRouters,'-----')
} else {
accessedRouters = filterAsyncRouter(asyncRouterMap, roles)
console.log(accessedRouters)
}
commit('SET_ROUTERS', accessedRouters)
resolve()
})
}
......
......@@ -83,7 +83,7 @@ const user = {
reject('error')
}
const data = response.data.data.data
data.roles = ['admin']
// data.roles = ['admin']
if (data.roles && data.roles.length > 0) { // 验证返回的roles是否是一个非空数组
commit('SET_ROLES', data.roles)
} else {
......
......@@ -23,8 +23,8 @@ export default {
])
},
created() {
if (!this.roles.includes('admin')) {
this.currentRole = 'editorDashboard'
if (!this.roles.includes('staff')) {
this.currentRole = 'adminDashboard'
}
}
}
......
......@@ -48,17 +48,21 @@
<el-table-column align="center" label="用户数">
<template slot-scope="scope">
<router-link :to="{path: '/user/list/', query: {group_id: scope.row.id}}" class="link-type">
<router-link :to="{path: '/user/list/', query: {group_id: scope.row.id}}" class="link-type" v-if="this.adminRole">
<span>{{ scope.row.user_nums }}</span>
</router-link>
<span v-else>{{ scope.row.user_nums }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="帖子数">
<template slot-scope="scope">
<router-link :to="{path: '/topic/list/', query: {group_id: scope.row.id}}" class="link-type">
<router-link :to="{path: '/topic/list/', query: {group_id: scope.row.id}}" class="link-type" v-if="this.adminRole">
<span>{{ scope.row.topic_nums }}</span>
</router-link>
<span v-else>{{ scope.row.topic_nums }} </span>
</template>
</el-table-column>
......@@ -89,6 +93,7 @@
</template>
<script>
import { mapGetters } from 'vuex'
import { fetchList, OffLineOrOnLine } from '@/api/group'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import waves from '@/directive/waves'
......@@ -104,15 +109,12 @@ export default {
0: 'info',
}
return statusMap[status]
},
genderFilter(status) {
const statusMap = {
'男': 'success',
'女': 'info',
'全部': 'danger'
}
return statusMap[status]
},
}
},
computed: {
...mapGetters([
'roles'
])
},
data() {
return {
......
......@@ -131,6 +131,10 @@ export default {
},
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() {
......
......@@ -407,6 +407,7 @@
temp: {
user_id: '',
content: '',
be_replied_id: '',
},
dialogFormVisible: false,
dialogStatus: '',
......@@ -675,11 +676,13 @@
this.temp = {
user_id: '',
content: '',
be_replied_id: '',
}
},
reply(row) {
this.resetTemp()
if (row){
// this.temp.be_replied_id = row.be_reply_user.id
this.temp.replied_id = row.id
}
this.dialogStatus = 'create'
......
......@@ -45,7 +45,8 @@
</el-row>
<el-row>
<el-col :span="12">
<el-form-item style="margin-bottom: 20px;" label-width="75px" label="用户名:" prop="nick_name">
<el-form-item style="margin-bottom: 20px;" label-width="75px" label="*用户名:" prop="nick_name">
<el-input v-model="postForm.nick_name" type="text" style="width: 230px"/>
</el-form-item>
</el-col>
......@@ -70,7 +71,7 @@
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label-width="75px" label="性别:" prop="gender">
<el-form-item label-width="75px" label="*性别:" prop="gender">
<el-select v-model="postForm.gender" :placeholder="'性别:'" clearable
class="postInfo-container-item"
style="width: 230px">
......@@ -80,7 +81,7 @@
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label-width="75px" label="城市:">
<el-form-item label-width="75px" label="*城市:">
<el-select v-model="city" :remote-method="getRemoteCityList" filterable remote clearable
value-key="id"
placeholder="搜索城市" style="width: 230px">
......@@ -125,7 +126,7 @@
</el-row>
<div style="margin-bottom: 20px;">
<el-form-item style="margin-bottom: 40px;" label-width="75px" label="用户头像:" prop="avatar">
<el-form-item style="margin-bottom: 40px;" label-width="85px" label="*用户头像:" prop="avatar">
<span v-model="uploadType"></span>
<Upload v-model="postForm.avatar" :uploadType="uploadType"/>
</el-form-item>
......@@ -160,6 +161,7 @@
password: '',
avatar: '',
nick_name: '',
gender: '',
tags: [],
is_puppet: 1,
......@@ -248,6 +250,7 @@
this.loading = false
return false
}
console.log(this.postForm.gender)
if (this.postForm.gender === ''){
this.$message.error('性别必填~')
this.loading = false
......
......@@ -110,6 +110,7 @@
import {fetchList, OffLineOrOnLine} from '@/api/user'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import waves from '@/directive/waves'
import { mapGetters } from 'vuex'
export default {
name: 'UserList',
......@@ -134,6 +135,7 @@
directives: {waves},
data() {
return {
adminRole: true,
list: null,
total: 0,
listLoading: true,
......@@ -174,6 +176,11 @@
created() {
this.getList()
},
computed: {
...mapGetters([
'roles'
])
},
methods: {
getList() {
this.listLoading = true
......
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