国家医疗器械不良事件监测信息系统用户操作手册_v20181220.docx
<div class="outer">
<div class="table-header">
<div class="select1">
线别:
<nz-select
nzShowSearch
nzAllowClear
nzPlaceHolder="搜索线别"
[(ngModel)]="selectedLine"
style="width: 100%;"
>
<nz-option *ngFor="let option of lines" [nzLabel]="option" [nzValue]="option" ></nz-option>
</nz-select>
</div>
<div class="select2">
机种:
<nz-select nzShowSearch nzAllowClear nzPlaceHolder="搜索机种" [(ngModel)]="selectedModel" style="width: 100%;">
<nz-option *ngFor="let option of models" [nzLabel]="option" [nzValue]="option"></nz-option>
</nz-select>
</div>
<div class="headerButton">
<button nz-button nzType="primary" (click)="searchLineAndModel()" style="margin-left: 5%;">
<i nz-icon nzType="search"></i>
搜 索
</button>
<button nz-button nzType="primary" (click)="addData()" style="margin-left: 5%;">
<i nz-icon nzType="plus-square" nzTheme="outline"></i>
添 加
</button>
<button nz-button nzType="primary" (click)="deleteSelect()" style="margin-left: 5%;">
<i nz-icon nzType="delete" nzTheme="outline"></i>
删除所选数据
</button>
<button nz-button nzType="primary" (click)="showModal()" style="margin-left: 5%;">
<i nz-icon nzType="upload" nzTheme="outline"></i>
上 传
</button>
</div>
</div>
<div class="tebal-content">
<nz-table
#rowSelectionTable
[nzData]="listOfData"
[nzScroll]="{ y: '480px' }"
(nzCurrentPageDataChange)="onCurrentPageDataChange($event)"
nzShowSizeChanger
>
<thead>
<tr>
<!-- <th
[nzSelections]="listOfSelection"
[(nzChecked)]="checked"
[nzIndeterminate]="indeterminate"
(nzCheckedChange)="onAllChecked($event)"
></th> -->
<th
[(nzChecked)]="checked"
[nzIndeterminate]="indeterminate"
(nzCheckedChange)="onAllChecked($event)"
></th>
<th>厂区</th>
<th>厂别</th>
<th>线种</th>
<th>机种</th>
<th>站别</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let data of rowSelectionTable.data">
<!-- <td [nzChecked]="setOfCheckedId.has(data.id)" (nzCheckedChange)="onItemChecked(data.id, $event)"></td> -->
<td
[nzChecked]="setOfCheckedId.has(data.station_id)"
[nzIndeterminate]="indeterminate"
(nzCheckedChange)="onItemChecked(data.station_id, $event)"
></td>
<td>{{ data.site }}</td>
<td>{{ data.plant }}</td>
<td>{{ data.line }}</td>
<td>{{ data.model }}</td>
<td>{{ data.station }}</td>
<td class="cell">
<em
nz-icon
nzType="more"
nzTheme="outline"
nz-popover
nzPopoverTrigger="hover"
(nzPopoverVisibleChange)="change($event)"
[nzPopoverContent]="contentTemplate"
nzPopoverPlacement="left"
></em>
<!-- 操作 -->
<ng-template #contentTemplate>
<a class="selectsadd" (click)="deleteModal(data.station_id)">删除</a><br>
<a class="selectsadd" (click)="update(data.station_id)">更新</a><br>
<a class="selectsadd" (click)="downLoad(data)">下載</a>
</ng-template>
</td>
</tr>
</tbody>
</nz-table>
<!-- <span>共{{ listOfData.length }}笔资料</span> -->
</div>
</div>
<!-- 上传弹出框 -->
<div>
<nz-modal
nzTitle="上传"
[(nzVisible)]="uploadVisible"
(nzOnCancel)="handleCancel()"
(nzOnOk)="handleOk()"
[nzStyle]="{ width: '30%', top: '100px' }"
[nzMaskStyle]="{ 'background-color': '#666' }"
[nzFooter]="nzModalFooter"
>
<ng-container *nzModalContent>
<nz-upload
nzType="drag"
[nzShowUploadList]="showUploadProgress"
[(nzFileList)]="fileList"
[nzLimit]="0"
[nzBeforeUpload]="beforeUpload"
[nzMultiple]="true"
[nzRemove]="delFileFromList"
>
<div class="upload-text">
<em nz-icon nzType="paper-clip" nzTheme="outline"></em>
<span>选择或拖拽上传</span>
</div>
</nz-upload>
</ng-container>
<ng-template #nzModalFooter>
<button
class="cancel"
nz-button
nzType="primary"
(click)="handleCancel()"
>
取消
</button>
<button [disabled]="flag" nz-button nzType="primary" (click)="handleOk()">
確定
</button>
</ng-template>
</nz-modal>
</div>
import { Component, OnInit } from '@angular/core';
import { HttpserviceService } from 'src/app/services/httpservice.service';
import { NzMessageService } from 'ng-zorro-antd/message'; //信息提示
import { NzModalService } from 'ng-zorro-antd/modal';
import { NzUploadFile } from 'ng-zorro-antd/upload';//上传
interface ItemData {
station_id: number;
site: string;
plant: number;
line: string;
model: string;
station: string;
}
@Component({
selector: 'app-mytemplate',
templateUrl: './mytemplate.component.html',
styleUrls: ['./mytemplate.component.css']
})
export class MytemplateComponent implements OnInit {
selectedLine = null;//搜索线别
selectedModel = null;//搜索机种
lines = new Set<number>(); //线别数组
models = new Set<number>(); //机种数组
deleteVisible = false;//删除提示框
checked = false;//控制单选
indeterminate = false;//
public listOfData:any[] = [];//所有数据
listOfCurrentPageData: readonly ItemData[] = [];//指定类型数组
checkedAll = false; //控制全选
setOfCheckedId = new Set<number>();//已选的数据
//上传数据
uploadVisible = false;//上传弹出框
flag = true;
fileList: NzUploadFile[] = [];
data: any = {
fileList: [],
isUploadXML: false// 是否上传了XML檔
};
showUploadProgress = true; //是否展示uploadList
//item的删除
delete(id: number, event: any){
console.log("删除");
this.listOfData = this.listOfData.filter((item) => item.station_id !== id);
}
//item的更新
update(id: any) {
console.log("更新");
this.listOfData.forEach((ele) => {
if (ele.station_id == id) {
ele.site = 'WCQ';
ele.plant = 'F715';
ele.line = "line";
ele.model = "model";
ele.station = 'station';
}
});
}
//item的下载
downLoad(data: any) {
console.log("下载");
let downLoadData = [];
downLoadData.push(data);
// this.downloadService.exportAsExcelFile(downLoadData, '表格数据');
}
//操作
change(event: any) {
console.log(event);
}
//全选
onAllChecked(isCheckAll: boolean): void {
this.listOfData.forEach(element => {
this.updateCheckedSet(element.station_id, isCheckAll);
});
this.refreshCheckedStatus();
this.checkedAll = isCheckAll;
}
//单选
onItemChecked(id: number, checked: boolean): void {
this.updateCheckedSet(id, checked);
this.refreshCheckedStatus();
if (checked) {
this.setOfCheckedId.add(id);
} else {
this.setOfCheckedId.delete(id);
}
console.log("setOfCheckedId:",this.setOfCheckedId);
console.log("id:",id);
}
//更新已选行的id列表
updateCheckedSet(id: number, checked: boolean): void {
if (checked) {
this.setOfCheckedId.add(id);
} else {
this.setOfCheckedId.delete(id);
}
}
//每页显示多少数据
onCurrentPageDataChange($event: readonly ItemData[]): void {
this.listOfCurrentPageData = $event;
this.refreshCheckedStatus();
}
//刷新table表
refreshCheckedStatus(): void {
this.checked = this.listOfCurrentPageData.every(item => this.setOfCheckedId.has(item.station_id));
this.indeterminate = this.listOfCurrentPageData.some(item => this.setOfCheckedId.has(item.station_id)) && !this.checked;
}
//删除本条数据
deleteModal(id: number): void {
this.modal.confirm({
nzTitle: '<i>警告</i>',
nzContent: '<b>是否确认删除本条数据?</b>',
nzOnOk: () => {
this.delete(id,true)
this.nzMessageService.success('删除成功!');
// console.log("this.listOfData:",this.listOfData);
}
});
}
//搜索线种和机种
searchLineAndModel(){
if(this.selectedLine!=null || this.selectedModel!=null){
let tempTable:any[]=[]
this.listOfData.forEach(element => {
if(this.selectedLine==element.line && this.selectedModel==element.model){
tempTable.push(element)
}
else if(this.selectedLine==null){
if(this.selectedModel==element.model){
tempTable.push(element)
}
}
else if(this.selectedModel==null){
if(this.selectedLine==element.line){
tempTable.push(element)
}
}
})
this.listOfData = tempTable
}else{
this.getTable();
}
//搜索完清空
this.selectedLine = null;
this.selectedModel = null;
this.refreshCheckedStatus()
}
//增加数据
addData() {
this.listOfData.push({
station_id: Math.floor(Math.random() * 100),
site: 'WCD',
plant: 'F721',
line: 'E1A',
model: 'SP15',
});
console.log(this.listOfData);
// this.refreshCheckedStatus()
}
//删除当前所选数据
deleteSelect() {
[...this.setOfCheckedId].forEach((id) => {
this.listOfData = this.listOfData.filter((item) => item['station_id'] !== id);
});
if (this.checkedAll) {
this.listOfData = [];
}
}
/**
* 上传弹出框
*/
showModal(): void {
this.uploadVisible = true;
console.log("this.listOfData:",this.listOfData);
}
handleOk(): void {
this.uploadVisible = false;
}
handleCancel(): void {
this.uploadVisible = false;
}
//上传
beforeUpload = (file: NzUploadFile): boolean => {
this.fileList = this.fileList.concat(file);
console.log('档案', file);
console.log(this.fileList);
if (file['type'] === 'text/xml') {
this.flag = false;
//callAPI
} else {
this.nzMessageService.create('error', '该档案不是xml类型');
}
return false;
};
//移出
delFileFromList = (file: NzUploadFile): boolean => {
console.log(file)
this.fileList.forEach((element, index) => {
if (element.uid == file.uid) {
this.fileList.splice(index, 1);
}
});
return true;
}
constructor(
private HttpService:HttpserviceService,
private nzMessageService: NzMessageService,
private modal: NzModalService
) {}
ngOnInit(){
this.getTable();
}
//调用Linlin的table的api
getTable(){
// await this.HttpService.getTableData().subscribe(
// res=>{
// console.log('res:',res.data);
// this.listOfData = res.data;
// }
// )
this.listOfData=[
{
station_id:1,
site:"WCD",
plant:1,
line:"A1",
model:"B1",
station:"C1",
},{
station_id:2,
site:"WCD",
plant:2,
line:"A1",
model:"B2",
station:"C2",
},{
station_id:3,
site:"WCD",
plant:3,
line:"A3",
model:"B3",
station:"C3",
},{
station_id:4,
site:"WCD",
plant:4,
line:"A4",
model:"B3",
station:"C4",
},{
station_id:5,
site:"WCD",
plant:5,
line:"A5",
model:"B5",
station:"C5",
},{
station_id:6,
site:"WCD",
plant:6,
line:"A6",
model:"B6",
station:"C6",
},{
station_id:7,
site:"WCD",
plant:7,
line:"A7",
model:"B7",
station:"C7",
},{
station_id:8,
site:"WCD",
plant:8,
line:"A8",
model:"B8",
station:"C8",
},{
station_id:9,
site:"WCD",
plant:9,
line:"A9",
model:"B9",
station:"C9",
},{
station_id:10,
site:"WCD",
plant:10,
line:"A10",
model:"B10",
station:"C10",
},{
station_id:11,
site:"WCD",
plant:11,
line:"A11",
model:"B11",
station:"C11",
}
]
//存储线种,机种
this.listOfData.forEach(element => {
this.lines.add(element.line);
this.models.add(element.model)
});
}
xxx(){
console.log('selectedLine:',this.selectedLine);
}
}
@import "~ng-zorro-antd/style/index.min.css"; /* 引入基本样式 */
@import "~ng-zorro-antd/button/style/index.min.css"; /* 引入组件样式 */
.outer{
height: 100%;
position: relative;
}
.table-header{
/* border: 1px solid rebeccapurple; */
width: 100%;
height: 10%;
position: relative;
}
.select1{
/* border: 1px solid red; */
width: 15%;
position: absolute;
margin: auto;
left: 5%;
top: 8%;
}
.select2{
/* border: 1px solid red; */
width: 15%;
position: absolute;
margin: auto;
left: 25%;
top: 8%;
}
.headerButton{
/* border: 1px solid rebeccapurple; */
/* width: 80%; */
height: 100%;
position: absolute;
margin: auto;
left: 40%;
right: 1px;
padding-top: 26px;
/* position: relative; */
}
.tebal-content{
/* border: 1px solid skyblue; */
width: 100%;
height: 90%;
position: absolute;
margin: auto;
top: 10%;
}
.selectsadd {
color: #40a9ff !important;
}
.selectsadd:hover {
color: white !important;
background: #40a9ff;
}
新建项目:ng new 项目名称
建立component、directive等schemastic:ng g schemastic名 名称
启动服务:ng serve 默认4200端口 +—port 指定端口/+—open直接打开
打包:ng build
插值语法:{{xxx}},直接读到component.ts里面的值
指令语法:
- ngif,else:就是if:条件为布尔值,false时不加载:ngif=”xxx”;else=”yyy”
- ngfor:就是循环:ngfor=”let item of list;let i = index”
数据绑定:
- 单向绑定:
- 基本的单项绑定:[]:[src]=”url”
- 类绑定:动态选择样式:[ngClass]={“class1=true,class2=false”}
- 样式绑定:控制大小等样式:[ngStyle]=”{color=xxx}”
- 双向绑定:输入框等信息:[(ngmodel)]=”xxx”
表单:
- 响应式表单
- 模板驱动表单
事件处理:
- 鼠标事件:
- 单击触发:(click)=”xxx()”
- 双击触发:(dblclick)=”xxx()”
- 失去焦点:(blur)=”xxx()”
- 鼠标进入:(mouseenter)=”xxx()”
- 鼠标离开:(mouseleave)=”xxx()”
- 鼠标滚动:(wheel)=”xxx()”
- 滑动条滚动:(scroll)=”xxx()”
- … …
- 键盘事件:
- 抬起触发:(keyup)=”xxx()”
- 按下触发:(keydown)=”xxx()”,(keypress)=”xxx()”
- enter抬起监听:(keyup.enter)=”xxx()”
- esc抬起触发:(keyup.esc)=”xxx()”
… …
- tab需配合keydown使用,无法配合keyup。
组件通信
- 父传子:父组件在子组件标签内传值,子组件中引入Input,用@Input接收值
- 子传父:子组件引入Output和EventEmitter,并实例化EventEmitter,通过this.new EventEmitter().emit(“xxx”)发送数据,
- 父调子:父组件在子组件标签内定义一个名如:#son,父组件引入viewChild,
- 任意组件传值:
路由:单页面应用实现跳转
- 创建路由:ng new 项目名 —routing
服务:
- 创建服务:ng g s 服务名
- 组件引入服务并注册
- 组件使用:result = this.服务.get/post(“url”,{参数})