This commit is contained in:
caoqianming 2020-06-08 17:23:49 +08:00
parent 77c776824d
commit 1661f3deeb
12 changed files with 243 additions and 21 deletions

View File

@ -7,6 +7,14 @@ export function getCMAList(query) {
params: query
})
}
export function getCNASList(query) {
return request({
url: '/ability/cnas/',
method: 'get',
params: query
})
}
export function createCMA(data) {
return request({
url: '/ability/cma/',
@ -34,4 +42,11 @@ export function importCMA(data) {
method: 'post',
data
})
}
export function importCNAS(data) {
return request({
url: `/ability/cnas/import/`,
method: 'post',
data
})
}

View File

@ -41,7 +41,7 @@ Vue.prototype.openLoading = function() {
})
setTimeout(function () { // 设定定时器超时5S后自动关闭遮罩层避免请求失败时遮罩层一直存在的问题
loading.close(); // 关闭遮罩层
},20000)
},50000)
return loading;
}
new Vue({

View File

@ -50,7 +50,7 @@ export const constantRoutes = [
path: 'cma',
name: 'CMA',
component: () => import('@/views/ability/cma'),
meta: { title: 'CMA检测能力', icon: 'table' }
meta: { title: '检测能力', icon: 'table' }
}]
}
// {

View File

@ -61,7 +61,7 @@ service.interceptors.response.use(
duration: 5 * 1000
})
// return Promise.reject(new Error(res.error || '请求出错'))
return Promise.reject(new Error(res.msg || '请求出错'))
} else {
return res
}

View File

@ -23,7 +23,7 @@
>刷新重置</el-button>
</div>
<div style="margin-top:10px">
<el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-if="checkPermission(['cma_create'])">新增</el-button>
<!-- <el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-if="checkPermission(['cma_create'])">新增</el-button> -->
<el-popover
placement="top"
width="160"
@ -43,7 +43,28 @@
</el-upload>
</div>
<el-button slot="reference">导入能力</el-button>
<el-button slot="reference">导入CMA能力</el-button>
</el-popover>
<el-popover
placement="top"
width="160"
v-if="checkPermission(['ability_import'])"
v-model="popovervisible2"
>
<p>导入能力列表压缩包.</p>
<div style="text-align: left; margin: 0;">
<el-upload
:action="upUrl"
:on-success="handleUploadSuccess2"
accept=".rar"
:headers="upHeaders"
:show-file-list ="false"
>
<el-button size="small" type="primary" @click="popovervisible2 = false">上传导入</el-button>
</el-upload>
</div>
<el-button slot="reference">导入CNAS能力</el-button>
</el-popover>
</div>
<el-table
@ -54,7 +75,7 @@
fit
stripe
highlight-current-row
max-height="600"
max-height="260"
>
<el-table-column type="index" width="50" />
<el-table-column align="center" label="大类名称">
@ -109,6 +130,60 @@
@pagination="getList"
/>
<el-table
v-loading="listLoading2"
:data="cnasList.results"
style="width: 100%;margin-top:10px;"
border
fit
stripe
highlight-current-row
max-height="260"
>
<el-table-column type="index" width="50" />
<el-table-column align="header-center" label="类别名称">
<template slot-scope="scope">{{ scope.row.lbmc }}</template>
</el-table-column>
<el-table-column align="header-center" label="项目名称">
<template slot-scope="scope">{{ scope.row.xmmc }}</template>
</el-table-column>
<el-table-column align="header-center" label="标准名称">
<template slot-scope="scope">{{ scope.row.bzmc }}</template>
</el-table-column>
<el-table-column align="header-center" label="标准编号">
<template slot-scope="scope">{{ scope.row.bzbh }}</template>
</el-table-column>
<el-table-column align="header-center" label="所属中心">
<template slot-scope="scope">{{ scope.row.sszx }}</template>
</el-table-column>
<el-table-column align="center" label="操作">
<template slot-scope="scope">
<el-button
:disabled="!checkPermission(['cnas_update'])"
type="primary"
size="small"
icon="el-icon-edit"
@click="handleEdit(scope)"
/>
<el-button
:disabled="!checkPermission(['cnas_delete'])"
type="danger"
size="small"
icon="el-icon-delete"
@click="handleDelete(scope)"
/>
</template>
</el-table-column>
</el-table>
<pagination
v-show="cnasList.count>0"
:total="cnasList.count"
:page.sync="listQuery2.page"
:limit.sync="listQuery2.page_size"
@pagination="getList2"
/>
<el-dialog :visible.sync="dialogVisible" :title="dialogType==='edit'?'编辑':'新增'">
<el-form ref="Form" :model="cma" label-width="80px" label-position="right" >
<el-form-item label="姓名" prop="name">
@ -126,7 +201,7 @@
</div>
</template>
<script>
import { getCMAList, createCMA, deleteCMA, updateCMA, importCMA } from "@/api/cma";
import { getCMAList, createCMA, deleteCMA, updateCMA, importCMA, getCNASList, importCNAS } from "@/api/cma";
import checkPermission from "@/utils/permission"
import { upUrl, upHeaders } from "@/api/file"
import Pagination from "@/components/Pagination" // secondary package based on el-pagination
@ -144,11 +219,16 @@ export default {
upHeaders: upHeaders(),
upUrl: upUrl(),
cmaList: {count:0},
cnasList: {count:0},
listLoading: true,
listQuery: {
page: 1,
page_size: 20
},
listQuery2: {
page: 1,
page_size: 20
},
enabledOptions: [
{ key: "true", display_name: "激活" },
{ key: "false", display_name: "禁用" }
@ -156,33 +236,41 @@ export default {
dialogVisible: false,
dialogType: "new",
popovervisible: false,
popovervisible2: false,
};
},
computed: {},
watch: {},
watch: {
},
created() {
this.getList()
this.getList2()
},
methods: {
checkPermission,
handleUploadSuccess(res, file) {
if (res.code >= 200) {
const loading = this.openLoading()
let data = {path:res.data.path}
importCMA(data).then(res=>{
if(res.code >= 200){
this.$message({
message: '导入成功',
type: 'success'
})
loading.close()
this.resetFilter()
}
}).catch(error=>{loading.close()})
},
handleUploadSuccess2(res, file) {
const loading = this.openLoading()
let data = {path:res.data.path}
importCNAS(data).then(res=>{
this.$message({
message: '导入成功',
type: 'success'
})
}else{
this.$message.error("解析失败!");
}
loading.close()
this.resetFilter()
}).catch(error=>{loading.close()})
},
getList() {
this.listLoading = true;
@ -193,16 +281,33 @@ export default {
this.listLoading = false
})
},
getList2() {
this.listLoading2 = true;
getCNASList(this.listQuery2).then(response => {
if (response.data) {
this.cnasList = response.data
}
this.listLoading2 = false
})
},
resetFilter() {
this.listQuery = {
page: 1,
page_size: 20
}
this.listQuery2 = {
page: 1,
page_size: 20
}
this.getList()
this.getList2()
},
handleFilter() {
this.listQuery.page = 1
this.getList()
this.listQuery2.page = 1
this.listQuery2.search = this.listQuery.search
this.getList2()
},
handleAdd() {
this.cma = Object.assign({}, defaultCMA)

View File

@ -0,0 +1,31 @@
# Generated by Django 3.0.5 on 2020-06-08 07:04
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('ability', '0004_auto_20200602_1715'),
]
operations = [
migrations.CreateModel(
name='CNAS',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('create_time', models.DateTimeField(default=django.utils.timezone.now, help_text='创建时间', verbose_name='创建时间')),
('update_time', models.DateTimeField(auto_now=True, help_text='修改时间', verbose_name='修改时间')),
('is_deleted', models.BooleanField(default=False, help_text='删除标记', verbose_name='删除标记')),
('lbmc', models.CharField(blank=True, max_length=200, null=True, verbose_name='类别名称')),
('xmmc', models.CharField(blank=True, max_length=200, null=True, verbose_name='项目名称')),
('bzmc', models.CharField(blank=True, max_length=400, null=True, verbose_name='标准名称')),
('bzbh', models.CharField(blank=True, max_length=400, null=True, verbose_name='标准编号')),
('sszx', models.TextField(blank=True, null=True, verbose_name='所属中心')),
],
options={
'abstract': False,
},
),
]

View File

@ -17,3 +17,13 @@ class CMA(BaseModel):
xzfw = models.TextField('限制范围',null=True,blank=True)
bz = models.TextField('备注',null=True,blank=True)
sszx = models.TextField('所属中心',null=True,blank=True)
class CNAS(BaseModel):
"""
CNAS检测能力表
"""
lbmc = models.CharField('类别名称', max_length=200,null=True,blank=True)
xmmc = models.CharField('项目名称', max_length=200,null=True,blank=True)
bzmc = models.CharField('标准名称', max_length=400,null=True,blank=True)
bzbh = models.CharField('标准编号', max_length=400,null=True,blank=True)
sszx = models.TextField('所属中心',null=True,blank=True)

View File

@ -1,5 +1,5 @@
from rest_framework import serializers
from .models import CMA
from .models import CMA, CNAS
class CMASerializer(serializers.ModelSerializer):
"""
@ -7,4 +7,12 @@ class CMASerializer(serializers.ModelSerializer):
"""
class Meta:
model = CMA
fields = '__all__'
class CNASSerializer(serializers.ModelSerializer):
"""
CNAS能力表序列化
"""
class Meta:
model = CNAS
fields = '__all__'

View File

@ -1,9 +1,10 @@
from django.urls import path, include
from rest_framework import routers
from .views import CMAViewSet
from .views import CMAViewSet, CNASViewSet
router = routers.DefaultRouter()
router.register('cma', CMAViewSet, basename="cma")
router.register('cnas', CNASViewSet, basename="cnas")
urlpatterns = [
path('', include(router.urls))
]

View File

@ -1,7 +1,7 @@
from django.shortcuts import render
from rest_framework.viewsets import ModelViewSet
from .models import CMA
from .serializers import CMASerializer
from .models import CMA, CNAS
from .serializers import CMASerializer, CNASSerializer
from rest_framework.decorators import action
from django.conf import settings
from rest_framework import status
@ -43,6 +43,40 @@ class CMAViewSet(ModelViewSet):
import_cma(f, os.path.join(root,f))
return Response(status = status.HTTP_200_OK)
class CNASViewSet(ModelViewSet):
"""
CNAS检测能力增删改查
"""
perms_map = {'get': '*', 'post': 'cnas_create',
'put': 'cnas_update', 'delete': 'cnas_delete'}
queryset = CNAS.objects.all()
serializer_class = CNASSerializer
search_fields = ['bzbh', 'bzmc', 'sszx', 'xmmc']
ordering_fields = ['bzmc']
ordering = 'bzmc'
@action(methods=['post'], detail=False, url_path='import', url_name='cnas_import', perms_map = {'post':'cnas_import'})
def cnas_import(self, request, pk=None):
"""
导入能力
"""
filepath = request.data['path']
fullpath = settings.BASE_DIR + filepath
import os
if fullpath.endswith('.rar'):
rar = rarfile.RarFile(fullpath)
fulldir = fullpath.replace('.rar','')
os.mkdir(fulldir)
os.chdir(fulldir)
rar.extractall()
rar.close()
CNAS.objects.all().delete()
for root, dirs, files in os.walk(fulldir):
for f in files:
if f.endswith('.xls'):
return Response('不支持旧xls格式', status = status.HTTP_400_BAD_REQUEST)
import_cnas(f, os.path.join(root,f))
return Response(status = status.HTTP_200_OK)
def import_cma(filename, path):
wb = load_workbook(path)
@ -66,4 +100,22 @@ def import_cma(filename, path):
print(data)
datalist.append(CMA(**data))
i = i + 1
CMA.objects.bulk_create(datalist)
CMA.objects.bulk_create(datalist)
def import_cnas(filename, path):
wb = load_workbook(path)
sheet = wb.get_sheet_by_name('检测能力范围')
datalist = []
sszx = filename.replace('.xlsx','').replace('检测能力范围(含能源之星)-','')
i = 3
while sheet['l'+str(i)].value:
data = {}
data['lbmc'] = sheet['b'+str(i)].value
data['xmmc'] = sheet['g'+str(i)].value
data['bzmc'] = sheet['l'+str(i)].value
data['bzbh'] = sheet['n'+str(i)].value
data['sszx'] = sszx
print(data)
datalist.append(CNAS(**data))
i = i + 1
CNAS.objects.bulk_create(datalist)

Binary file not shown.

View File

@ -3,4 +3,4 @@ from rest_framework.pagination import PageNumberPagination
class MyPagination(PageNumberPagination):
page_size = 10
page_size_query_param = 'limit'
page_size_query_param = 'page_size'