Commit 43bce44b by Nakarin Luankla

UPDATE ส่ง type file

parent 41b485e9
...@@ -133,7 +133,7 @@ ...@@ -133,7 +133,7 @@
<label for="name" class="col-sm-4 col-form-label">ไฟล์อัพโหลด</label> <label for="name" class="col-sm-4 col-form-label">ไฟล์อัพโหลด</label>
<div class="{{!modelExcel.excelObj||!checkEdit ? 'col-sm-8' : 'col-sm-6'}}"> <div class="{{!modelExcel.excelObj||!checkEdit ? 'col-sm-8' : 'col-sm-6'}}">
<input type="file" class="form-control" (change)="onSelectFile($event)"> <input type="file" class="form-control" (change)="onSelectFile($event)">
<div class="msg-detail">ไฟล์ที่อนุญาต:*.xlsx</div> <div class="msg-detail">ไฟล์ที่อนุญาต:*.xlsx *.xlsm</div>
</div> </div>
<div class="col-auto" *ngIf="modelExcel.excelObj&&checkEdit"> <div class="col-auto" *ngIf="modelExcel.excelObj&&checkEdit">
<button class="btn btn-primary" (click)="downloadFile(modelExcel.logId)"><i class="fas fa-download" ></i></button> <button class="btn btn-primary" (click)="downloadFile(modelExcel.logId)"><i class="fas fa-download" ></i></button>
......
...@@ -74,15 +74,17 @@ export class ListExcelComponent implements OnInit { ...@@ -74,15 +74,17 @@ export class ListExcelComponent implements OnInit {
if (event.target.files && event.target.files[0]) { if (event.target.files && event.target.files[0]) {
const reader = new FileReader(); const reader = new FileReader();
const file: File = event.target.files[0]; const file: File = event.target.files[0];
console.log("🚀 ~ ListExcelComponent ~ onSelectFile ~ file:", file.type)
reader.readAsDataURL(event.target.files[0]); // read file as data url reader.readAsDataURL(event.target.files[0]); // read file as data url
reader.onload = (event) => { // called once readAsDataURL is completed reader.onload = (event) => { // called once readAsDataURL is completed
if(event){ if(event){
const allowedTypes = ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']; const allowedTypes = ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.ms-excel.sheet.macroEnabled.12'];
if (!allowedTypes.includes(file.type)) { if (!allowedTypes.includes(file.type)) {
this.openAlertModal('อัพโหลดได้เฉพาะไฟล์ *.xlsx เท่านั้น') this.openAlertModal('อัพโหลดได้เฉพาะไฟล์ *.xlsx *.xlsm เท่านั้น')
} else { } else {
let base64 = event.target!.result as string let base64 = event.target!.result as string
this.modelExcel.excelObj = base64.split(',')[1]; this.modelExcel.excelObj = base64.split(',')[1];
this.modelExcel.fileType = file.type
} }
} }
} }
......
...@@ -24,6 +24,7 @@ export interface ExcelModel { ...@@ -24,6 +24,7 @@ export interface ExcelModel {
approveTime: string approveTime: string
tags: TagModel[] tags: TagModel[]
group: GroupModel group: GroupModel
fileType: string
} }
export class ExcelModel implements ExcelModel { export class ExcelModel implements ExcelModel {
...@@ -48,6 +49,7 @@ export class ExcelModel implements ExcelModel { ...@@ -48,6 +49,7 @@ export class ExcelModel implements ExcelModel {
approveTime: string approveTime: string
tags: TagModel[] tags: TagModel[]
group: GroupModel group: GroupModel
fileType: string
constructor(data: Partial<any>) { constructor(data: Partial<any>) {
this.logId = data.logId?data.logId:'' this.logId = data.logId?data.logId:''
this.thumbnail = data.thumbnail?data.thumbnail:'' this.thumbnail = data.thumbnail?data.thumbnail:''
...@@ -70,6 +72,7 @@ export class ExcelModel implements ExcelModel { ...@@ -70,6 +72,7 @@ export class ExcelModel implements ExcelModel {
this.approveDate = data.approveDate?data.approveDate:'' this.approveDate = data.approveDate?data.approveDate:''
this.approveTime = data.approveTime?data.approveTime:'' this.approveTime = data.approveTime?data.approveTime:''
this.group = data.group?new GroupModel(data.group):new GroupModel({}) this.group = data.group?new GroupModel(data.group):new GroupModel({})
this.fileType = data.fileType?data.fileType:''
} }
getImage(){ getImage(){
if(this.thumbnail){ if(this.thumbnail){
......
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