parent
b10a40d177
commit
2feda8800c
@ -0,0 +1,25 @@ |
||||
import request from '@/utils/request' |
||||
|
||||
export function getDomainInfos(query) { |
||||
return request({ |
||||
url: '/domain/info', |
||||
method: 'get', |
||||
params: query |
||||
}) |
||||
} |
||||
|
||||
export function updateDomainInfo(data) { |
||||
return request({ |
||||
url: '/domain/info', |
||||
method: 'put', |
||||
data |
||||
}) |
||||
} |
||||
|
||||
export function deleteDomain(data) { |
||||
return request({ |
||||
url: '/domain/info', |
||||
method: 'delete', |
||||
data |
||||
}) |
||||
} |
@ -0,0 +1,145 @@ |
||||
<template> |
||||
<div class="app-container"> |
||||
<el-form ref="postForm" :model="postForm" label-width="100px" :disabled="!is_edit"> |
||||
<el-row> |
||||
<el-col :span="12"> |
||||
<el-form-item label="用户ID"> |
||||
<el-row :gutter="12"> |
||||
<el-col :span="16"> |
||||
<el-input :value="postForm.user_id" disabled /> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
<el-form-item v-if="postForm.app_info&& postForm.app_info.app_id" label="应用ID"> |
||||
<el-row :gutter="12"> |
||||
<el-col :span="16"> |
||||
<el-input v-model="postForm.app_id" disabled /> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
|
||||
<el-form-item v-if="postForm.app_info&& postForm.app_info.app_id" label="应用名称"> |
||||
<el-row :gutter="12"> |
||||
<el-col :span="16"> |
||||
<el-input v-model="postForm.app_info.name" disabled /> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
<el-form-item label="域名类型"> |
||||
<el-row :gutter="12"> |
||||
<el-col :span="16"> |
||||
<el-select v-model="postForm.domain_type" class="filter-item" disabled> |
||||
<el-option v-for="item in postForm.domain_type_choices" :key="item.id" :label="item.name" :value="item.id" /> |
||||
</el-select> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
<el-form-item label="创建时间" prop="timestamp"> |
||||
<el-row :gutter="20"> |
||||
<el-col :span="8"> |
||||
<el-date-picker :value="postForm.created_time" type="datetime" disabled /> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
|
||||
</el-col> |
||||
<el-col :span="12"> |
||||
|
||||
<el-form-item label="绑定的域名" label-width="160px"> |
||||
<el-row :gutter="12"> |
||||
<el-col :span="16"> |
||||
<el-input v-model="postForm.domain_name" /> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
|
||||
<el-form-item label="绑定状态" label-width="160px"> |
||||
<el-row :gutter="12"> |
||||
<el-col :span="16"> |
||||
<el-select v-model="postForm.is_enable" class="filter-item"> |
||||
<el-option v-for="item in domain_state_choices" :key="item.id" :label="item.name" :value="item.id" /> |
||||
</el-select> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
<el-form-item label="CnameID" label-width="160px"> |
||||
<el-row :gutter="12"> |
||||
<el-col :span="16"> |
||||
<el-input v-model="postForm.cname_id" disabled /> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form> |
||||
<el-col :span="9" style="float: right"> |
||||
<el-button v-if="!is_edit" type="primary" :disabled="postForm.id === postForm.used_id" @click="is_edit=true">修改</el-button> |
||||
<div v-else> |
||||
<el-button type="primary" @click="is_edit=false">取消</el-button> |
||||
<el-button type="primary" @click="updateData">保存修改</el-button> |
||||
</div> |
||||
</el-col> |
||||
</div> |
||||
</template> |
||||
|
||||
<script> |
||||
import { getDomainInfos, updateDomainInfo } from '@/api/domain' |
||||
const domain_state_choices = [ |
||||
{ id: false, name: '继续绑定' }, |
||||
{ id: true, name: '绑定成功' } |
||||
] |
||||
const defaultForm = { |
||||
user_id: undefined, |
||||
app_info: undefined, |
||||
domain_type: undefined, |
||||
domain_name: undefined, |
||||
cname_id: undefined, |
||||
is_enable: undefined, |
||||
domain_type_choices: undefined, |
||||
created_time: undefined |
||||
} |
||||
|
||||
export default { |
||||
name: 'OrderDetail', |
||||
components: { }, filters: {}, |
||||
data() { |
||||
return { |
||||
postForm: Object.assign({}, defaultForm), |
||||
loading: false, |
||||
is_edit: false, |
||||
domain_state_choices |
||||
} |
||||
}, |
||||
computed: {}, |
||||
created() { |
||||
const id = this.$route.params && this.$route.params.id |
||||
this.fetchData(id) |
||||
}, |
||||
methods: { |
||||
fetchData(id) { |
||||
getDomainInfos({ id: id }).then(response => { |
||||
if (response.data.length === 1) { |
||||
this.postForm = response.data[0] |
||||
} |
||||
}).catch(err => { |
||||
console.log(err) |
||||
}) |
||||
}, |
||||
updateData() { |
||||
updateDomainInfo(this.postForm).then(response => { |
||||
this.$message.success('更新成功') |
||||
this.postForm = response.data |
||||
}).catch(err => { |
||||
console.log(err) |
||||
}) |
||||
} |
||||
} |
||||
} |
||||
</script> |
||||
|
||||
<style scoped> |
||||
.editor-container { |
||||
position: relative; |
||||
height: 100%; |
||||
} |
||||
</style> |
@ -0,0 +1,193 @@ |
||||
<template> |
||||
<div class="app-container"> |
||||
<div class="filter-container"> |
||||
<el-input v-model="listQuery.user_id" placeholder="用户ID" style="width: 140px;" class="filter-item" clearable @keyup.enter.native="handleFilter" /> |
||||
<el-input v-model="listQuery.domain_name" placeholder="下载域名" style="width: 300px;" class="filter-item" clearable @keyup.enter.native="handleFilter" /> |
||||
<el-input v-model="listQuery.app_name" placeholder="应用名称" style="width: 200px;" class="filter-item" clearable @keyup.enter.native="handleFilter" /> |
||||
<el-select v-model="listQuery.domain_type" placeholder="下载域名类型" clearable class="filter-item" style="width: 140px" @change="handleFilter"> |
||||
<el-option v-for="item in domain_type_choices" :key="item.id" :label="item.name" :value="item.id" /> |
||||
</el-select> |
||||
<el-select v-model="listQuery.is_enable" placeholder="域名绑定状态" clearable class="filter-item" style="width: 140px" @change="handleFilter"> |
||||
<el-option v-for="item in domain_state_choices" :key="item.id" :label="item.name" :value="item.id" /> |
||||
</el-select> |
||||
<el-select v-model="listQuery.sort" style="width: 140px" class="filter-item" @change="handleFilter"> |
||||
<el-option v-for="item in sortOptions" :key="item.key" :label="item.label" :value="item.key" /> |
||||
</el-select> |
||||
<el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter"> |
||||
Search |
||||
</el-button> |
||||
</div> |
||||
<el-table |
||||
v-loading="listLoading" |
||||
:data="list" |
||||
element-loading-text="Loading" |
||||
border |
||||
fit |
||||
highlight-current-row |
||||
stripe |
||||
> |
||||
<el-table-column align="center" label="ID" width="90"> |
||||
<template slot-scope="scope"> |
||||
{{ scope.row.id }} |
||||
</template> |
||||
</el-table-column> |
||||
<el-table-column label="用户ID" width="100" align="center"> |
||||
<template slot-scope="scope"> |
||||
<router-link :to="{name: 'user_info_edit',params:{id:scope.row.user_id}}"> |
||||
<el-link type="primary"> {{ scope.row.user_id }}</el-link> |
||||
</router-link> |
||||
</template> |
||||
</el-table-column> |
||||
<el-table-column label="下载域名" min-width="280px"> |
||||
<template slot-scope="scope"> |
||||
{{ scope.row.domain_name }} |
||||
</template> |
||||
</el-table-column> |
||||
|
||||
<el-table-column class-name="status-col" label="下载域名类型" width="160" align="center"> |
||||
<template slot-scope="scope"> |
||||
<router-link v-if="scope.row.domain_type===2" :to="{name: 'app_info_list',params:{user_id:scope.row.user_id,app_id:scope.row.app_id}}"> |
||||
<el-tag :type="scope.row.domain_type | domainStatusFilter">{{ scope.row| domainLableFilter }}</el-tag> |
||||
</router-link> |
||||
<el-tag v-else :type="scope.row.domain_type | domainStatusFilter">{{ scope.row| domainLableFilter }}</el-tag> |
||||
|
||||
</template> |
||||
</el-table-column> |
||||
<el-table-column class-name="status-col" label="绑定状态" width="95" align="center"> |
||||
<template slot-scope="scope"> |
||||
<el-tag :type="scope.row.is_enable | statusFilter">{{ scope.row| statusLableFilter }}</el-tag> |
||||
</template> |
||||
</el-table-column> |
||||
<el-table-column align="center" prop="created_time" label="创建时间" width="120"> |
||||
<template slot-scope="scope"> |
||||
<i class="el-icon-time" /> |
||||
<el-tooltip :content="scope.row.created_time"> |
||||
<span>{{ scope.row.created_time|formatTime }}</span> |
||||
</el-tooltip> |
||||
</template> |
||||
</el-table-column> |
||||
<el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width"> |
||||
<template slot-scope="scope"> |
||||
<router-link :to="{name: 'domain_info_edit',params:{id:scope.row.id}}"> |
||||
<el-button type="primary" size="mini"> |
||||
查看编辑 |
||||
</el-button> |
||||
</router-link> |
||||
<el-button type="danger" size="mini" @click="remove_domain(scope.row.id)"> |
||||
删除 |
||||
</el-button> |
||||
</template> |
||||
</el-table-column> |
||||
</el-table> |
||||
<pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="fetchData" /> |
||||
|
||||
</div> |
||||
</template> |
||||
|
||||
<script> |
||||
import { getDomainInfos, deleteDomain } from '@/api/domain' |
||||
import { baseFilter } from '@/utils' |
||||
import Pagination from '@/components/Pagination' // secondary package based on el-pagination |
||||
import waves from '@/directive/waves' // waves directive |
||||
|
||||
const sortOptions = [ |
||||
{ label: '创建时间 Ascending', key: 'created_time' }, |
||||
{ label: '创建时间 Descending', key: '-created_time' } |
||||
] |
||||
|
||||
const domain_state_choices = [ |
||||
{ id: false, name: '继续绑定' }, |
||||
{ id: true, name: '绑定成功' } |
||||
] |
||||
|
||||
export default { |
||||
name: 'DomainInfo', |
||||
components: { Pagination }, |
||||
directives: { waves }, |
||||
filters: { |
||||
formatTime(time) { |
||||
if (time) { |
||||
return time.split('T')[0] |
||||
} |
||||
}, |
||||
domainStatusFilter(status) { |
||||
const statusMap = { |
||||
'1': 'success', |
||||
'0': 'gray', |
||||
'2': 'info' } |
||||
return statusMap[status] |
||||
}, |
||||
domainLableFilter(row) { |
||||
if (row.domain_type === 2) { |
||||
return '应用' + row.app_info.name + '域名' |
||||
} |
||||
return baseFilter(row.domain_type, row.domain_type_choices) |
||||
}, |
||||
statusLableFilter(row) { |
||||
return baseFilter(row.is_enable, domain_state_choices) |
||||
}, |
||||
statusFilter(status) { |
||||
const statusMap = { |
||||
true: 'success', |
||||
false: 'danger' |
||||
} |
||||
return statusMap[status] |
||||
} |
||||
}, |
||||
data() { |
||||
return { |
||||
list: null, |
||||
listLoading: true, |
||||
total: 0, |
||||
listQuery: { |
||||
page: 1, |
||||
limit: 10, |
||||
user_id: undefined, |
||||
sort: '-created_time', |
||||
domain_name: undefined, |
||||
app_name: undefined, |
||||
domain_type: undefined, |
||||
is_enable: undefined |
||||
}, |
||||
sortOptions, |
||||
domain_type_choices: [], |
||||
domain_state_choices |
||||
} |
||||
}, |
||||
created() { |
||||
this.fetchData() |
||||
}, mounted() { |
||||
if (this.$route.params.user_id) { |
||||
this.listQuery.user_id = this.$route.params.user_id |
||||
} |
||||
console.log(this.$router) |
||||
}, |
||||
methods: { |
||||
remove_domain(domain_id) { |
||||
deleteDomain({ id: domain_id }).then(response => { |
||||
this.list = response.data |
||||
if (this.list && this.list.length > 0) { |
||||
this.domain_type_choices = this.list[0].domain_type_choices |
||||
} |
||||
this.total = response.total |
||||
this.listLoading = false |
||||
}) |
||||
}, |
||||
handleFilter() { |
||||
this.listQuery.page = 1 |
||||
this.fetchData() |
||||
}, |
||||
fetchData() { |
||||
this.listLoading = true |
||||
getDomainInfos(this.listQuery).then(response => { |
||||
this.list = response.data |
||||
if (this.list && this.list.length > 0) { |
||||
this.domain_type_choices = this.list[0].domain_type_choices |
||||
} |
||||
this.total = response.total |
||||
this.listLoading = false |
||||
}) |
||||
} |
||||
} |
||||
} |
||||
</script> |
@ -0,0 +1,83 @@ |
||||
#!/usr/bin/env python |
||||
# -*- coding:utf-8 -*- |
||||
# project: 4月 |
||||
# author: liuyu |
||||
# date: 2021/4/11 |
||||
|
||||
from api.models import UserDomainInfo |
||||
from rest_framework.response import Response |
||||
from api.utils.auth import AdminTokenAuthentication |
||||
from api.utils.serializer import AdminDomainNameSerializer |
||||
from rest_framework.views import APIView |
||||
from api.utils.response import BaseResponse |
||||
from api.utils.storage.caches import del_cache_response_by_short, reset_app_wx_easy_type |
||||
import logging |
||||
from rest_framework.pagination import PageNumberPagination |
||||
from api.utils.baseutils import get_dict_from_filter_fields |
||||
from api.base_views import app_delete |
||||
|
||||
logger = logging.getLogger(__name__) |
||||
|
||||
|
||||
class PageNumber(PageNumberPagination): |
||||
page_size = 20 # 每页显示多少条 |
||||
page_size_query_param = 'limit' # URL中每页显示条数的参数 |
||||
page_query_param = 'page' # URL中页码的参数 |
||||
max_page_size = None # 最大页码数限制 |
||||
|
||||
|
||||
class DomainNameInfoView(APIView): |
||||
authentication_classes = [AdminTokenAuthentication, ] |
||||
|
||||
def get(self, request): |
||||
res = BaseResponse() |
||||
filter_fields = ["id", "domain_name", "app_name", "domain_type", "user_id", "is_enable"] |
||||
filter_data = get_dict_from_filter_fields(filter_fields, request.query_params) |
||||
app_name = filter_data.get('app_name', None) |
||||
if app_name: |
||||
filter_data["app_id__name__contains"] = filter_data['app_name'] |
||||
del filter_data['app_name'] |
||||
sort = request.query_params.get("sort", "-created_time") |
||||
page_obj = PageNumber() |
||||
obj_list = UserDomainInfo.objects.filter(**filter_data).order_by(sort) |
||||
page_serializer = page_obj.paginate_queryset(queryset=obj_list, request=request, |
||||
view=self) |
||||
serializer = AdminDomainNameSerializer(page_serializer, many=True) |
||||
res.data = serializer.data |
||||
res.total = obj_list.count() |
||||
return Response(res.dict) |
||||
|
||||
def put(self, request): |
||||
res = BaseResponse() |
||||
data = request.data |
||||
pk = data.get("id", None) |
||||
if not pk: |
||||
res.code = 1003 |
||||
res.msg = "参数错误" |
||||
return Response(res.dict) |
||||
obj = UserDomainInfo.objects.filter(pk=pk).first() |
||||
if obj: |
||||
data['pk'] = pk |
||||
serializer_obj = AdminDomainNameSerializer(obj, data=data, partial=True) |
||||
if serializer_obj.is_valid(): |
||||
serializer_obj.save() |
||||
res.data = serializer_obj.data |
||||
reset_app_wx_easy_type(obj.user_id, obj.app_id) |
||||
return Response(res.dict) |
||||
res.code = 1004 |
||||
res.msg = "数据校验失败" |
||||
return Response(res.dict) |
||||
|
||||
def delete(self, request): |
||||
res = BaseResponse() |
||||
data = request.data |
||||
pk = data.get("id", None) |
||||
if not pk: |
||||
res.code = 1003 |
||||
res.msg = "参数错误" |
||||
else: |
||||
user_domain_obj = UserDomainInfo.objects.filter(pk=pk).first() |
||||
reset_app_wx_easy_type(user_domain_obj.user_id, user_domain_obj.app_id) |
||||
user_domain_obj.delete() |
||||
return self.get(request) |
||||
return Response(res.dict) |
Loading…
Reference in new issue