parent
ac77e8b36a
commit
ef5d434c40
@ -1,77 +0,0 @@ |
||||
<template> |
||||
<div class="json-editor"> |
||||
<textarea ref="textarea" /> |
||||
</div> |
||||
</template> |
||||
|
||||
<script> |
||||
import CodeMirror from 'codemirror' |
||||
import 'codemirror/addon/lint/lint.css' |
||||
import 'codemirror/lib/codemirror.css' |
||||
import 'codemirror/theme/rubyblue.css' |
||||
require('script-loader!jsonlint') |
||||
import 'codemirror/mode/javascript/javascript' |
||||
import 'codemirror/addon/lint/lint' |
||||
import 'codemirror/addon/lint/json-lint' |
||||
|
||||
export default { |
||||
name: 'JsonEditor', |
||||
/* eslint-disable vue/require-prop-types */ |
||||
props: ['value'], |
||||
data() { |
||||
return { |
||||
jsonEditor: false |
||||
} |
||||
}, |
||||
watch: { |
||||
value(value) { |
||||
const editorValue = this.jsonEditor.getValue() |
||||
if (value !== editorValue) { |
||||
this.jsonEditor.setValue(JSON.stringify(this.value, null, 2)) |
||||
} |
||||
} |
||||
}, |
||||
mounted() { |
||||
this.jsonEditor = CodeMirror.fromTextArea(this.$refs.textarea, { |
||||
lineNumbers: true, |
||||
mode: 'application/json', |
||||
gutters: ['CodeMirror-lint-markers'], |
||||
theme: 'rubyblue', |
||||
lint: true |
||||
}) |
||||
|
||||
this.jsonEditor.setValue(JSON.stringify(this.value, null, 2)) |
||||
this.jsonEditor.on('change', cm => { |
||||
this.$emit('changed', cm.getValue()) |
||||
this.$emit('input', cm.getValue()) |
||||
}) |
||||
}, |
||||
methods: { |
||||
getValue() { |
||||
return this.jsonEditor.getValue() |
||||
} |
||||
} |
||||
} |
||||
</script> |
||||
|
||||
<style lang="scss" scoped> |
||||
.json-editor { |
||||
height: 100%; |
||||
position: relative; |
||||
|
||||
::v-deep { |
||||
.CodeMirror { |
||||
height: auto; |
||||
min-height: 300px; |
||||
} |
||||
|
||||
.CodeMirror-scroll { |
||||
min-height: 300px; |
||||
} |
||||
|
||||
.cm-s-rubyblue span.cm-string { |
||||
color: #F08047; |
||||
} |
||||
} |
||||
} |
||||
</style> |
@ -0,0 +1,183 @@ |
||||
<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 label="存储名称"> |
||||
<el-row :gutter="12"> |
||||
<el-col :span="16"> |
||||
<el-input v-model="postForm.name" /> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
<el-form-item label="存储类型"> |
||||
<el-row :gutter="12"> |
||||
<el-col :span="16"> |
||||
<el-select v-model="postForm.storage_type" class="filter-item" disabled> |
||||
<el-option v-for="item in postForm.storage_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-form-item label="更新时间" prop="timestamp"> |
||||
<el-row :gutter="20"> |
||||
<el-col :span="8"> |
||||
<el-date-picker :value="postForm.updated_time" type="datetime" disabled /> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
<el-form-item label="存储描述信息"> |
||||
<el-row :gutter="12"> |
||||
<el-col :span="16"> |
||||
<el-input v-model="postForm.description" :autosize="{ minRows: 4, maxRows: 6}" type="textarea" /> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
</el-col> |
||||
<el-col :span="12"> |
||||
|
||||
<el-form-item label="存储访问access_key" label-width="160px"> |
||||
<el-row :gutter="12"> |
||||
<el-col :span="16"> |
||||
<el-input v-model="postForm.access_key" /> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
<el-form-item label="存储访问secret_key" label-width="160px"> |
||||
<el-row :gutter="12"> |
||||
<el-col :span="16"> |
||||
<el-input v-model="postForm.secret_key" /> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
<el-form-item label="存储空间bucket_name" label-width="160px"> |
||||
<el-row :gutter="12"> |
||||
<el-col :span="16"> |
||||
<el-input v-model="postForm.bucket_name" /> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
<div v-if="postForm.storage_type===2"> |
||||
<el-form-item label="阿里云sts_role_arn" label-width="160px"> |
||||
<el-row :gutter="12"> |
||||
<el-col :span="16"> |
||||
<el-input v-model="postForm.sts_role_arn" /> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
|
||||
<el-form-item label="阿里云endpoint" label-width="160px"> |
||||
<el-row :gutter="12"> |
||||
<el-col :span="16"> |
||||
<el-input v-model="postForm.endpoint" /> |
||||
</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.download_auth_type" class="filter-item" style="width: 100%"> |
||||
<el-option v-for="item in postForm.download_auth_type_choices" :key="item.id" :label="item.name" :value="item.id" /> |
||||
</el-select> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
<el-form-item v-if="postForm.download_auth_type===2" label="阿里云cnd_auth_key" label-width="160px"> |
||||
<el-row :gutter="12"> |
||||
<el-col :span="16"> |
||||
<el-input v-model="postForm.cnd_auth_key" /> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form-item> |
||||
</div> |
||||
</el-col> |
||||
</el-row> |
||||
</el-form> |
||||
<el-col :span="9" style="float: right"> |
||||
<el-button v-if="!is_edit" type="primary" @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 { getStorageInfo, updateStorageInfo } from '@/api/storage' |
||||
|
||||
const defaultForm = { |
||||
user_id: undefined, |
||||
name: undefined, |
||||
storage_type: undefined, |
||||
access_key: undefined, |
||||
secret_key: undefined, |
||||
bucket_name: undefined, |
||||
domain_name: undefined, |
||||
created_time: undefined, |
||||
description: undefined, |
||||
sts_role_arn: undefined, |
||||
endpoint: undefined, |
||||
download_auth_type: undefined, |
||||
cnd_auth_key: undefined, |
||||
updated_time: undefined, |
||||
download_auth_type_choices: [] |
||||
} |
||||
|
||||
export default { |
||||
name: 'StorageDetail', |
||||
components: { }, filters: {}, |
||||
data() { |
||||
return { |
||||
postForm: Object.assign({}, defaultForm), |
||||
loading: false, |
||||
is_edit: false |
||||
} |
||||
}, |
||||
computed: {}, |
||||
created() { |
||||
const id = this.$route.params && this.$route.params.id |
||||
this.fetchData(id) |
||||
}, |
||||
methods: { |
||||
fetchData(id) { |
||||
getStorageInfo({ id: id }).then(response => { |
||||
if (response.data.length === 1) { |
||||
this.postForm = response.data[0] |
||||
} |
||||
}).catch(err => { |
||||
console.log(err) |
||||
}) |
||||
}, |
||||
updateData() { |
||||
updateStorageInfo(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,199 @@ |
||||
<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.bucket_name" placeholder="bucket_name" style="width: 300px;" class="filter-item" clearable @keyup.enter.native="handleFilter" /> |
||||
<el-input v-model="listQuery.access_key" placeholder="access_key" style="width: 200px;" class="filter-item" clearable @keyup.enter.native="handleFilter" /> |
||||
<el-input v-model="listQuery.name" placeholder="存储名称" style="width: 200px;" class="filter-item" clearable @keyup.enter.native="handleFilter" /> |
||||
<el-input v-model="listQuery.domain_name" placeholder="下载域名" style="width: 200px;" class="filter-item" clearable @keyup.enter.native="handleFilter" /> |
||||
<el-select v-model="listQuery.storage_type" placeholder="存储类型" clearable class="filter-item" style="width: 140px" @change="handleFilter"> |
||||
<el-option v-for="item in storage_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="存储名称"> |
||||
<template slot-scope="scope"> |
||||
{{ scope.row.name }} |
||||
</template> |
||||
</el-table-column> |
||||
<el-table-column label="存储访问access_key" align="center"> |
||||
<template slot-scope="scope"> |
||||
<span>{{ scope.row.access_key }}</span> |
||||
</template> |
||||
</el-table-column> |
||||
<el-table-column label="存储空间bucket_name" align="center"> |
||||
<template slot-scope="scope"> |
||||
{{ scope.row.bucket_name }} |
||||
</template> |
||||
</el-table-column> |
||||
<el-table-column label="下载域名" align="center"> |
||||
<template slot-scope="scope"> |
||||
{{ scope.row.domain_name }} |
||||
</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.storage_type | certStatusFilter">{{ scope.row| certLableFilter }}</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 align="center" prop="created_time" label="更新时间" width="120"> |
||||
<template slot-scope="scope"> |
||||
<i class="el-icon-time" /> |
||||
<el-tooltip :content="scope.row.updated_time"> |
||||
<span>{{ scope.row.updated_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: 'storage_info_edit',params:{id:scope.row.id}}"> |
||||
<el-button type="primary" size="mini"> |
||||
查看编辑 |
||||
</el-button> |
||||
</router-link> |
||||
<el-button type="danger" size="mini" @click="deleteApp(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 { getStorageInfo } from '@/api/storage' |
||||
import Pagination from '@/components/Pagination' // secondary package based on el-pagination |
||||
import waves from '@/directive/waves' // waves directive |
||||
|
||||
const sortOptions = [ |
||||
{ label: '创建时间 Ascending', key: 'reviewed_time' }, |
||||
{ label: '创建时间 Descending', key: '-reviewed_time' }, |
||||
{ label: '更新时间 Ascending', key: 'created_time' }, |
||||
{ label: '更新时间 Descending', key: '-created_time' } |
||||
] |
||||
|
||||
export default { |
||||
name: 'StorageInfo', |
||||
components: { Pagination }, |
||||
directives: { waves }, |
||||
filters: { |
||||
formatTime(time) { |
||||
return time.split('T')[0] |
||||
}, |
||||
certStatusFilter(status) { |
||||
const statusMap = { |
||||
'0': 'danger', |
||||
'1': 'success', |
||||
'2': 'gray', |
||||
'3': 'info' |
||||
} |
||||
return statusMap[status] |
||||
}, |
||||
certLableFilter(row) { |
||||
for (const v of row.storage_choices) { |
||||
if (v.id === row.storage_type) { |
||||
return v.name |
||||
} |
||||
} |
||||
}, |
||||
statusFilter(status) { |
||||
const statusMap = { |
||||
true: 'success', |
||||
false: 'danger' |
||||
} |
||||
return statusMap[status] |
||||
}, |
||||
appStatusNameFilter(row) { |
||||
for (const r of row.status_choices) { |
||||
if (r.id === row.status) { |
||||
return r.name |
||||
} |
||||
} |
||||
}, |
||||
appStatusFilter(status) { |
||||
const statusMap = { |
||||
'0': 'danger', |
||||
'1': 'success', |
||||
'2': 'gray' |
||||
} |
||||
return statusMap[status] |
||||
} |
||||
}, |
||||
data() { |
||||
return { |
||||
list: null, |
||||
listLoading: true, |
||||
total: 0, |
||||
listQuery: { |
||||
page: 1, |
||||
limit: 10, |
||||
name: undefined, |
||||
sort: '-created_time', |
||||
bucket_name: undefined, |
||||
access_key: undefined, |
||||
storage_type: undefined, |
||||
domain_name: undefined, |
||||
user_id: undefined |
||||
}, |
||||
sortOptions, |
||||
storage_choices: [] |
||||
} |
||||
}, |
||||
created() { |
||||
this.fetchData() |
||||
}, |
||||
methods: { |
||||
handleFilter() { |
||||
this.listQuery.page = 1 |
||||
this.fetchData() |
||||
}, |
||||
fetchData() { |
||||
this.listLoading = true |
||||
getStorageInfo(this.listQuery).then(response => { |
||||
this.list = response.data |
||||
if (this.list && this.list.length > 0) { |
||||
this.storage_choices = this.list[0].storage_choices |
||||
} |
||||
this.total = response.total |
||||
this.listLoading = false |
||||
}) |
||||
} |
||||
} |
||||
} |
||||
</script> |
@ -0,0 +1,70 @@ |
||||
#!/usr/bin/env python |
||||
# -*- coding:utf-8 -*- |
||||
# project: 4月 |
||||
# author: liuyu |
||||
# date: 2021/4/11 |
||||
|
||||
from django.contrib import auth |
||||
from api.models import Token, UserInfo, APPSuperSignUsedInfo |
||||
from rest_framework.response import Response |
||||
from api.utils.auth import AdminTokenAuthentication |
||||
from api.utils.baseutils import get_dict_from_filter_fields |
||||
from api.utils.serializer import AdminStorageSerializer, AdminUserCertificationSerializer |
||||
from django.core.cache import cache |
||||
from rest_framework.views import APIView |
||||
import binascii |
||||
import os, datetime |
||||
from api.utils.utils import get_captcha, valid_captcha, get_choices_dict |
||||
from api.utils.response import BaseResponse |
||||
from fir_ser.settings import CACHE_KEY_TEMPLATE, LOGIN |
||||
from api.utils.storage.caches import login_auth_failed |
||||
import logging |
||||
from api.utils.throttle import VisitRegister1Throttle, VisitRegister2Throttle |
||||
from rest_framework.pagination import PageNumberPagination |
||||
|
||||
logger = logging.getLogger(__name__) |
||||
|
||||
|
||||
class AppsPageNumber(PageNumberPagination): |
||||
page_size = 20 # 每页显示多少条 |
||||
page_size_query_param = 'limit' # URL中每页显示条数的参数 |
||||
page_query_param = 'page' # URL中页码的参数 |
||||
max_page_size = None # 最大页码数限制 |
||||
|
||||
|
||||
class StorageInfoView(APIView): |
||||
authentication_classes = [AdminTokenAuthentication, ] |
||||
|
||||
def get(self, request): |
||||
res = BaseResponse() |
||||
filter_fields = ["id", "user_id", "name", "storage_type", "access_key", "bucket_name"] |
||||
filter_data = get_dict_from_filter_fields(filter_fields, request.query_params) |
||||
sort = request.query_params.get("sort", "-created_time") |
||||
page_obj = AppsPageNumber() |
||||
obj_list = AppStorage.objects.filter(**filter_data).order_by(sort) |
||||
page_serializer = page_obj.paginate_queryset(queryset=obj_list, request=request, |
||||
view=self) |
||||
serializer = AdminStorageSerializer(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 = AppStorage.objects.filter(pk=pk).first() |
||||
if obj: |
||||
data['pk'] = pk |
||||
serializer = AdminStorageSerializer(obj, data=data, partial=True) |
||||
if serializer.is_valid(): |
||||
serializer.save() |
||||
res.data = serializer.data |
||||
return Response(res.dict) |
||||
res.code = 1004 |
||||
res.msg = "数据校验失败" |
||||
return Response(res.dict) |
Loading…
Reference in new issue