156 lines
5.2 KiB
JavaScript
156 lines
5.2 KiB
JavaScript
define(["angularAMD"], function (angularAMD) {
|
|
angularAMD.service('mrs07Service', ['$rootScope', '$filter', '$translate', 'config', 'MMWService', '$mdDialog', '$timeout',
|
|
function($rootScope, $filter, $translate, config, $MMWService, $mdDialog, $timeout){
|
|
/***
|
|
* optins : {
|
|
* plotItem : {
|
|
* plot_no,
|
|
* op_seq,
|
|
* op_no
|
|
* work_station
|
|
* },
|
|
* close : function //關閉後呼叫的方法
|
|
* }
|
|
*/
|
|
this.init = function(options){
|
|
var mrs07dialog;
|
|
var openDialog = function(sopList){
|
|
$mdDialog.dialog('module/moduleWIP/program/common/mrs07/mrs07.html',
|
|
function(dialog){
|
|
mrs07dialog = dialog;
|
|
return {
|
|
esopList: sopList,
|
|
isListOpen:true,
|
|
currentFile:{},
|
|
beforeShown:function(){
|
|
loadESOPFile(sopList[0], dialog);
|
|
},
|
|
closeList:function(){
|
|
dialog.isListOpen = !dialog.isListOpen;
|
|
},
|
|
clickEsopFile : function(esopFile){
|
|
loadESOPFile(esopFile, dialog);
|
|
},
|
|
back: function () {
|
|
dialog.hide();
|
|
if(options.close)
|
|
options.close();
|
|
}
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
function loadESOPFile(esopFile, dialog){
|
|
if(esopFile.content_type == ''){
|
|
openFile(esopFile.esop_content);
|
|
} else {
|
|
dialog.currentFile = esopFile;
|
|
dialog.pdf_url = '';
|
|
dialog.video_url = '';
|
|
//document.getElementById('kmi-pdf-panel').innerHtml = '';
|
|
if(dialog.currentFile.content_type == '0'){
|
|
//PDF
|
|
dialog.pdf_url = 'JSplugins/pdfjs/web/viewer.html?file='+dialog.currentFile.esop_content
|
|
+'&openfile=false&viewbookmark=false&printfile=false&download=false#auto';
|
|
} else if(dialog.currentFile.content_type == '1'){
|
|
//影片
|
|
dialog.video_url = dialog.currentFile.esop_content.replace('http://', '');
|
|
$timeout(function () {
|
|
var VideoPanel = document.getElementById('kmi-video-panel');
|
|
VideoPanel.innerHTML = '';
|
|
VideoPanel.innerHTML = "<source src='"+dialog.currentFile.esop_content+"' type=\"video/mp4\">";
|
|
});
|
|
} else if(dialog.currentFile.content_type == '2'){
|
|
var kmiImgPanel = document.getElementById('kmi-img-panel');
|
|
kmiImgPanel.style.width = '100%';
|
|
kmiImgPanel.style.height = '100%';
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
function getFileContent(file_path){
|
|
var fileArray = file_path.split('/');
|
|
return {fileName : fileArray[fileArray.length-1]};
|
|
}
|
|
|
|
function openFile(file_url){
|
|
if($rootScope.platform == 'desktop'){
|
|
const{shell} = nodeRequire('electron')
|
|
var progress = nodeRequire('request-progress'),
|
|
request = nodeRequire('request'),
|
|
path = nodeRequire('path'),
|
|
fs = nodeRequire('fs');
|
|
$rootScope.showLoading();
|
|
$timeout(function(){
|
|
request(file_url).on('response', function(response){
|
|
try{
|
|
var sop_temppath = path.resolve('./temp_esop/');
|
|
if (!fs.existsSync(sop_temppath)) {
|
|
fs.mkdirSync(sop_temppath);
|
|
}
|
|
var file_local_path = path.join(sop_temppath, getFileContent(file_url).fileName);
|
|
response.pipe(fs.createWriteStream(file_local_path));
|
|
response.on('error', function (error) {
|
|
$rootScope.hideLoading();
|
|
$rootScope.showAlert($filter('translate')('mrs07.msg.cantDownloadFile')+file_url+'<br>'+error);
|
|
});
|
|
response.on('end', function(){
|
|
$rootScope.hideLoading();
|
|
shell.openItem(file_local_path);
|
|
});
|
|
}catch(e){
|
|
$rootScope.hideLoading();
|
|
};
|
|
}).on('error', function (error) {
|
|
$rootScope.hideLoading();
|
|
$rootScope.showAlert($filter('translate')('mrs07.msg.cantDownloadFile')+file_url+'<br>'+error);
|
|
});
|
|
});
|
|
} else {
|
|
$rootScope.showAlert($filter('translate')('mrs07.msg.cantOpenFile'));
|
|
}
|
|
}
|
|
|
|
function SopInfoGet(callback){
|
|
$MMWService.sendToEAISrv({
|
|
uri : 'KMI.esop_info_get_json',
|
|
content : {
|
|
plot_no : options.plotItem.plot_no,
|
|
op_seq : options.plotItem.sft_op_seq,
|
|
op_no : options.plotItem.sft_op_no,
|
|
work_station: config.cache.dashboard == 'lot' ? config.cache.op : config.cache.workStation, //20221123,13871,調整使用的opno
|
|
line_no: config.cache.dashboard == 'lot' ? config.cache.op : config.cache.workStation, //20221123,13871,調整使用的opno
|
|
machine_no: config.cache.equipment
|
|
},
|
|
success : function(data){
|
|
data = JSON.parse(data.Result);
|
|
if(data.Result != 'fail'){
|
|
if(callback)
|
|
callback(data);
|
|
} else {
|
|
$rootScope.showAlert(data.SysMsg, options.close);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
SopInfoGet(function(data){
|
|
var esop_details = data.esop_info_get;
|
|
if(esop_details && esop_details.length > 0){
|
|
if(esop_details.length == 1 && esop_details[0].content_type == ''){
|
|
openFile(esop_details[0].esop_content);
|
|
} else {
|
|
openDialog(esop_details);
|
|
}
|
|
|
|
} else {
|
|
$rootScope.showAlert($filter('translate')('common.msg.no_data'), options.close);
|
|
}
|
|
});
|
|
return mrs07dialog;
|
|
};
|
|
}]);
|
|
});
|