优化woker

This commit is contained in:
24kycj
2024-12-02 12:55:52 +08:00
parent ba2579642d
commit dd7bce6b40
5 changed files with 266 additions and 70 deletions
+45 -16
View File
@@ -5,42 +5,45 @@
</template> </template>
<script> <script>
const dayjs = require('dayjs')
export default { export default {
name: 'App', name: 'App',
mounted() { mounted() {
if (this.$store.getters.token) { let that = this
this.$store.dispatch('chat/initWebSocket') // 初始化websocket if (that.$store.getters.token) {
that.$store.dispatch('chat/initWebSocket') // 初始化websocket
} }
}, },
watch: { watch: {
'$store.state.chat.printer_error': { '$store.state.chat.printer_error': {
handler(val) { handler(val) {
console.log(val) let that = this
const currentTime = dayjs().format('hh:mm:ss');
if (val.message) { if (val.message) {
this.$message({ that.$message({
message: val.message, message: val.message,
type: val.type, type: val.type,
}) })
} }
if (val.notify) { if (val.notify) {
this.$notify({ that.$notify({
title: '温馨提示', title: '温馨提示' + currentTime,
message: val.notify, message: val.notify,
type: val.type, type: val.type,
duration: 0 duration: 0
}) })
} }
if (val.confirm) { if (val.confirm) {
this.$confirm(val.confirm, '温馨提示', { that.$notify({
confirmButtonText: '重试', title: '温馨提示:' + currentTime,
closeOnClickModal: false, duration: 0,
closeOnPressEscape: false, dangerouslyUseHTMLString: true,
showClose: false, message: `<div class="notify_text">${val.confirm}</div><div class="notify_btns"><div class="notify_btn notify_btn2" id="notifyAgain" data-type="continue_task">重试</div></div>`,
type: 'warning' onClick(event) {
}).then(() => {
if (val.req && val.req === 'continue_task') { if (val.req && val.req === 'continue_task') {
// 下一个任务 // 下一个任务
this.$store.dispatch('chat/websocketsend', { that.$store.dispatch('chat/websocketsend', {
req_name: 'continue_task', req_name: 'continue_task',
req_type: 1, req_type: 1,
req_info: {} req_info: {}
@@ -50,8 +53,8 @@ export default {
}) })
} }
}).catch(() => { this.close()
}
}); });
} }
}, },
@@ -64,4 +67,30 @@ export default {
</script> </script>
<style lang="scss"> <style lang="scss">
@use './styles/index.scss'; // 全局自定义的css样式 @use './styles/index.scss'; // 全局自定义的css样式
.el-notification__group {
width: 100%;
}
.notify_btns{
display: flex;
align-items: center;
justify-content: end;
padding: 10px 0 0;
gap: 14px;
.notify_btn {
width: 60px;
height: 30px;
line-height: 30px;
text-align: center;
font-size: 14px;
border-radius: 4px;
cursor: pointer;
}
.notify_btn1 {
border: 1px solid #ccc;
}
.notify_btn2 {
background-color: #409EFF;
color: #fff;
}
}
</style> </style>
@@ -45,7 +45,7 @@ export default {
if (size == -1) { if (size == -1) {
return '正在计算...'; return '正在计算...';
} }
return bytesToSize(size); return this.$filterSize(size);
}, },
getIcon(name) { getIcon(name) {
if (this.info.folder) { if (this.info.folder) {
+124 -10
View File
@@ -186,7 +186,7 @@
</div> </div>
</div> </div>
<div class="flex_box footer_btns"> <div class="flex_box footer_btns">
<!-- <el-button type="primary" class="footer_save" @click="workSave" :loading="saveFlag">保存</el-button> --> <el-button type="primary" class="footer_save" @click="workSave" :loading="saveFlag">保存</el-button>
<el-button type="primary" class="footer_submit" @click="workSubmit" :loading="submitFlag">提交</el-button> <el-button type="primary" class="footer_submit" @click="workSubmit" :loading="submitFlag">提交</el-button>
</div> </div>
</div> </div>
@@ -213,6 +213,14 @@ import files from './files/file'
export default { export default {
name: 'UserInfo', name: 'UserInfo',
components: { fileEmpty, files }, components: { fileEmpty, files },
props: {
saveWorkList: {
type: Object | undefined
},
isNew: {
type: Boolean
},
},
data() { data() {
return { return {
addShow: false, addShow: false,
@@ -410,6 +418,57 @@ export default {
}, },
deep: true, deep: true,
immediate: true immediate: true
},
isNew: {
immediate: true,
handler(val) {
let that = this
that.$nextTick(function () {
if (!that.isNew) {
that.isNew = true
that.$nextTick(() => {
that.$refs.files.allSize = that.saveWorkList.size
that.$refs.files.allNumber = that.saveWorkList.filesList.length
that.$refs.files.filesList = that.saveWorkList.filesList
})
that.soonList = that.saveWorkList.soonList
that.soonImg = that.saveWorkList.soonImg
that.totalSize = that.saveWorkList.totalSize
for (let key in that.form) {
that.form[key] = that.saveWorkList[key]
}
that.form.task_name = that.saveWorkList.task_name
if (that.saveWorkList.json_file) {
fs.readFile(that.saveWorkList.json_file, 'utf8', (err, data) => {
if (err) {
console.error('读取文件时出错:', err)
return
}
let name = that.saveWorkList.json_file.split('\\')[1]
that.fileLists[0] = new File([data], name, {
type: ''
})
// that.readFile(data)
})
}
if (that.saveWorkList.udf_file) {
that.csvIsExist = true
console.log(that.saveWorkList.udf_file, that.csvIsExist)
fs.readFile(that.saveWorkList.udf_file, 'utf8', (err, data) => {
if (err) {
console.error('读取文件时出错:', err)
return
}
let name = that.saveWorkList.udf_file.split('\\')[1]
that.file_name = name
that.fileLists[0] = new File([data], name, {
type: ''
})
})
}
}
})
}
} }
}, },
computed: { computed: {
@@ -447,10 +506,60 @@ export default {
async upload_over() {}, async upload_over() {},
// 保存 // 保存
workSave() { workSave() {
that.saveFlag = true let that = this
setTimeout(() => { if (that.form.json_file === '' && that.$refs.files.filesList.length === 0) {
that.saveFlag = false that.$message({
}, 1000) message: '请上传作业文件',
type: 'warning'
})
return
}
let t = true
for (let i in that.$refs.files.filesList) {
if (that.$refs.files.filesList[i].size == -1) {
t = false
}
}
if (t) {
let save = {...that.form}
save.filesList = that.$refs.files.getLists()
save.totalSize = that.totalSize
if (that.soonList.length > 0) {
that.soonList.forEach((item) => {
if (item.type == 1&&that.$refs[item.origin_name][0].files[0]) {
item.val = that.$refs[item.origin_name][0].files[0].path
}
if (!item.val) {
item.val = item.default || ''
}
})
}
save.soonImg = that.soonImg
save.soonList = that.soonList
console.log(save)
const v = JSON.stringify(save)
dialog
.showSaveDialog({
title: 'Save',
filters: [{ name: 'Soon Work', extensions: ['swk'] }]
})
.then((result) => {
fs.writeFileSync(result.filePath, v)
that.$message({
message: '保存成功',
type: 'success'
})
})
.catch((err) => {
console.log(err)
})
} else {
that.$message({
offset: 100,
message: '请等待计算',
type: 'warning'
})
}
}, },
// 提交 // 提交
workSubmit() { workSubmit() {
@@ -552,6 +661,7 @@ export default {
that.form.ass_task.push(task) that.form.ass_task.push(task)
} }
// csv文件处理 // csv文件处理
console.log(that.form.udf_file, that.soonList)
if (!that.form.udf_file && that.soonList.length > 0) { if (!that.form.udf_file && that.soonList.length > 0) {
that.soonList.forEach((item) => { that.soonList.forEach((item) => {
if (item.type == 1&&that.$refs[item.origin_name][0].files[0]) { if (item.type == 1&&that.$refs[item.origin_name][0].files[0]) {
@@ -564,6 +674,8 @@ export default {
let csv1 = that.soonList.map(item => item.origin_name).join(',') let csv1 = that.soonList.map(item => item.origin_name).join(',')
let csv2 = that.soonList.map(item => item.val).join(',') let csv2 = that.soonList.map(item => item.val).join(',')
that.csvForm.req_info.file_text = csv1 + '\n' + csv2 that.csvForm.req_info.file_text = csv1 + '\n' + csv2
console.log(that.csvForm.req_info.file_text)
return
that.$store.dispatch('chat/websocketsend', that.csvForm).then(() => { that.$store.dispatch('chat/websocketsend', that.csvForm).then(() => {
}).catch(() => { }).catch(() => {
@@ -722,10 +834,12 @@ export default {
//let flag = true; //校验结果 //let flag = true; //校验结果
let first_line = this.result.split('\n')[0].replace('\r', '').split(',') //第一行 let first_line = this.result.split('\n')[0].replace('\r', '').split(',') //第一行
let second_line = this.result.split('\n')[1].replace('\r', '').split(',') //第二行 let second_line = this.result.split('\n')[1].replace('\r', '').split(',') //第二行
let i = 0 console.log(first_line, second_line)
for (let item of first_line) { for (let i = 0; i < first_line.length; i++) {
that.$set(that.soonform, item, second_line[i]) let index = that.soonList.findIndex(soon => soon.origin_name === first_line[i])
i++ if(index > -1) {
that.soonList[index].val = second_line[i]
}
} }
that.csvIsExist = true that.csvIsExist = true
} }
@@ -1078,7 +1192,7 @@ export default {
font-weight: 500; font-weight: 500;
font-size: 16px; font-size: 16px;
color: #25aed9; color: #25aed9;
line-height: 30px; line-height: 40px;
text-align: center; text-align: center;
margin-left: 30px; margin-left: 30px;
} }
+33 -3
View File
@@ -157,6 +157,36 @@ const defaultData = {
// start_time: '2024-04-01 12:00:00', // start_time: '2024-04-01 12:00:00',
// finish_time: '2024-04-01 12:00:00', // finish_time: '2024-04-01 12:00:00',
// task_status: 2 // task_status: 2
// },
// {
// task_size: 100000,
// cd_type: 2,
// start_time: '2024-04-01 12:00:00',
// finish_time: '2024-04-01 12:00:00',
// task_status: 2
// }
// ]
// },
// {
// task_uuid: '202042152',
// task_name: '复制任务',
// finish_freq: 2,
// total_freq: 10,
// task_status: 2,
// ass_task: [
// {
// task_size: 100000,
// cd_type: 2,
// start_time: '2024-04-01 12:00:00',
// finish_time: '2024-04-01 12:00:00',
// task_status: 2
// },
// {
// task_size: 100000,
// cd_type: 2,
// start_time: '2024-04-01 12:00:00',
// finish_time: '2024-04-01 12:00:00',
// task_status: 2
// } // }
// ] // ]
// } // }
@@ -364,7 +394,7 @@ const actions = {
for (let i = 0; i < errors.length; i++) { for (let i = 0; i < errors.length; i++) {
if (errors[i] == 1) { if (errors[i] == 1) {
setTimeout(() => { setTimeout(() => {
commit('setData', { name: 'printer_error', data: {type: 'error', confirm: Error1[i], req: 'continue_task' } }) commit('setData', { name: 'printer_error', data: {type: 'error', notify: Error1[i] } })
}, 500); }, 500);
} }
} }
@@ -374,7 +404,7 @@ const actions = {
for (let i = 0; i < errors.length; i++) { for (let i = 0; i < errors.length; i++) {
if (errors[i] == 1) { if (errors[i] == 1) {
setTimeout(() => { setTimeout(() => {
commit('setData', { name: 'printer_error', data: {type: 'error', confirm: Error2[i], req: 'continue_task' } }) commit('setData', { name: 'printer_error', data: {type: 'error', notify: Error2[i] } })
}, 500); }, 500);
} }
} }
@@ -384,7 +414,7 @@ const actions = {
for (let i = 0; i < errors.length; i++) { for (let i = 0; i < errors.length; i++) {
if (errors[i] == 1) { if (errors[i] == 1) {
setTimeout(() => { setTimeout(() => {
commit('setData', { name: 'printer_error', data: {type: 'error', confirm: Error3[i], req: 'continue_task' } }) commit('setData', { name: 'printer_error', data: {type: 'error', notify: Error3[i] } })
}, 500); }, 500);
} }
} }
+53 -30
View File
@@ -121,7 +121,7 @@
<div class="device_info_option_b_text device_info_option_b_text1">{{ parseInt(printer_info.yellow_last) }}%</div> <div class="device_info_option_b_text device_info_option_b_text1">{{ parseInt(printer_info.yellow_last) }}%</div>
</div> </div>
<div v-if="isLast" @click="isLast = false" class="flex_box flex_row_center device_info_option_b"> <div v-if="isLast" @click="isLast = false" class="flex_box flex_row_center device_info_option_b">
<div class="device_info_option_b_text device_info_option_b_text1">{{ $accDiv($accAdd($accAdd(printer_info.blue_last,printer_info.red_last),printer_info.yellow_last),3).toFixed(2) }}%</div> <div class="device_info_option_b_text device_info_option_b_text1">{{ parseInt($accDiv($accAdd($accAdd(printer_info.blue_last,printer_info.red_last),printer_info.yellow_last),3)) }}%</div>
</div> </div>
</div> </div>
</div> </div>
@@ -163,10 +163,10 @@
<div class="flex_box device_right_top"> <div class="flex_box device_right_top">
<div class="flex_box flex_row_between device_right_top_item"> <div class="flex_box flex_row_between device_right_top_item">
<div class="device_right_top_img"> <div class="device_right_top_img">
<img v-if="cd_list[0].cd_status == 4" src="@/assets/images/device3.png" /> <img v-if="cd_list[0].cd_status == 4 && cd_list[0].cd_type" src="@/assets/images/device3.png" />
<img v-if="cd_list[0].cd_status != 4" src="@/assets/images/device2.png" /> <img v-else src="@/assets/images/device2.png" />
<div class="device_right_top_img_text" v-if="cd_list[0].cd_status != 4">{{ diskTypes[cd_list[0].dev_type] }}</div> <div class="device_right_top_img_text device_right_top_img_text1" v-if="cd_list[0].cd_status == 4 && cd_list[0].cd_type">{{ CDTypes[cd_list[0].cd_type] }}</div>
<div class="device_right_top_img_text device_right_top_img_text1" v-if="cd_list[0].cd_status == 4">{{ CDTypes[cd_list[0].cd_type] }}</div> <div class="device_right_top_img_text" v-else>{{ diskTypes[cd_list[0].dev_type] }}</div>
</div> </div>
<div class="device_right_top_content"> <div class="device_right_top_content">
<div class="device_right_top_title">{{ cd_list[0].dev_path || '' }}({{ $store.state.chat.CDName[cd_list[0].cd_pos] }})</div> <div class="device_right_top_title">{{ cd_list[0].dev_path || '' }}({{ $store.state.chat.CDName[cd_list[0].cd_pos] }})</div>
@@ -184,10 +184,10 @@
<div class="device_right_top_line"></div> <div class="device_right_top_line"></div>
<div class="flex_box flex_row_between device_right_top_item"> <div class="flex_box flex_row_between device_right_top_item">
<div class="device_right_top_img"> <div class="device_right_top_img">
<img v-if="cd_list[1].cd_status == 4" src="@/assets/images/device3.png" /> <img v-if="cd_list[1].cd_status == 4 && cd_list[1].cd_type" src="@/assets/images/device3.png" />
<img v-if="cd_list[1].cd_status != 4" src="@/assets/images/device2.png" /> <img v-else src="@/assets/images/device2.png" />
<div class="device_right_top_img_text" v-if="cd_list[1].cd_status != 4">{{ diskTypes[cd_list[1].dev_type] }}</div> <div class="device_right_top_img_text device_right_top_img_text1" v-if="cd_list[1].cd_status == 4 && cd_list[1].cd_type">{{ CDTypes[cd_list[1].cd_type] }}</div>
<div class="device_right_top_img_text device_right_top_img_text1" v-if="cd_list[1].cd_status == 4">{{ CDTypes[cd_list[1].cd_type] }}</div> <div class="device_right_top_img_text" v-else>{{ diskTypes[cd_list[1].dev_type] }}</div>
</div> </div>
<div class="device_right_top_content"> <div class="device_right_top_content">
<div class="device_right_top_title">{{ cd_list[1].dev_path || '' }}({{ $store.state.chat.CDName[cd_list[1].cd_pos] }})</div> <div class="device_right_top_title">{{ cd_list[1].dev_path || '' }}({{ $store.state.chat.CDName[cd_list[1].cd_pos] }})</div>
@@ -242,7 +242,7 @@
<div class="flex_box work_top"> <div class="flex_box work_top">
<div class="work_top_text">作业列表</div> <div class="work_top_text">作业列表</div>
</div> </div>
<el-table row-key="task_uuid" default-expand-all class="work_table" :data="task_list" empty-text="暂无作业列表" :tree-props="{children: 'ass_task', hasChildren: 'hasChildren'}"> <el-table row-key="id" default-expand-all class="work_table" :data="task_list" empty-text="暂无作业列表" :tree-props="{children: 'ass_task', hasChildren: 'hasChildren'}">
<!-- <el-table-column type="index" width="80" label="序号"></el-table-column> --> <!-- <el-table-column type="index" width="80" label="序号"></el-table-column> -->
<el-table-column prop="task_uuid" label="作业ID"></el-table-column> <el-table-column prop="task_uuid" label="作业ID"></el-table-column>
<el-table-column prop="task_name" label="任务名称"></el-table-column> <el-table-column prop="task_name" label="任务名称"></el-table-column>
@@ -285,15 +285,16 @@
</div> </div>
<!-- 新建作业 --> <!-- 新建作业 -->
<work-add v-if="workShow" @close="workShow=false" ref="workAdd"></work-add> <work-add v-if="workShow" @close="workShow=false" :isNew="isNew" :saveWorkList="saveWorkList" ref="workAdd"></work-add>
</div> </div>
</template> </template>
<script> <script>
let that let that
let outTimer let outTimer
let fs = require('fs')
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
const { app, dialog } = require('@electron/remote')
import UserInfo from '@/components/userInfo/userInfo.vue' import UserInfo from '@/components/userInfo/userInfo.vue'
import WorkAdd from '@/components/workAdd/workAdd.vue' import WorkAdd from '@/components/workAdd/workAdd.vue'
@@ -385,7 +386,9 @@ export default {
logList: [], logList: [],
allLogList: [], allLogList: [],
showAll: false, showAll: false,
workShow: false workShow: false,
isNew: true,
saveWorkList: {}
} }
}, },
watch: { watch: {
@@ -395,11 +398,12 @@ export default {
let tasks = [...val] let tasks = [...val]
let list = [] let list = []
tasks.forEach((item, index) => { tasks.forEach((item, index) => {
item.id = item.task_uuid
if (item.ass_task&&item.ass_task.length) { if (item.ass_task&&item.ass_task.length) {
let task_size = 0 let task_size = 0
item.ass_task.forEach((item2, idx) => { item.ass_task.forEach((item2, idx) => {
item2.task_uuid = item.task_uuid+'_'+(idx+1) item2.id = item.task_uuid+'_'+(idx+1)
item2.task_name = item.task_name+'_'+(idx+1) // item2.task_name = item.task_name+'_'+(idx+1)
task_size = this.$accAdd(task_size, item2.task_size) task_size = this.$accAdd(task_size, item2.task_size)
}) })
item.task_size = task_size item.task_size = task_size
@@ -651,13 +655,14 @@ export default {
}, },
// 新建作业 // 新建作业
showWork() { showWork() {
if (!that.workStatus) { // if (!that.workStatus) {
that.$message({ // that.$message({
message: '请先连接服务', // message: '请先连接服务',
type: 'warning' // type: 'warning'
}) // })
return // return
} // }
that.isNew = true
that.workShow = true that.workShow = true
that.$nextTick(() => { that.$nextTick(() => {
that.$refs.workAdd.show() that.$refs.workAdd.show()
@@ -665,13 +670,31 @@ export default {
}, },
// 打开作业文件 // 打开作业文件
openWork() { openWork() {
if (!that.workStatus) { // if (!that.workStatus) {
that.$message({ // that.$message({
message: '请先连接服务', // message: '请先连接服务',
type: 'warning' // type: 'warning'
// })
// return
// }
that.isNew = false
dialog
.showOpenDialog({
title: '打开作业文件',
filters: [{ name: 'Soon Work', extensions: ['swk'] }]
})
.then((res) => {
fs.readFile(res.filePaths[0], (err, data) => {
let fName = res.filePaths[0].trim()
let fileName = fName.substring(fName.lastIndexOf('\\') + 1)
that.saveWorkList = JSON.parse(data)
that.saveWorkList.task_name = fileName
that.workShow = true
that.$nextTick(() => {
that.$refs.workAdd.show()
})
})
}) })
return
}
}, },
// 显示日志 // 显示日志
noticeChange() { noticeChange() {
@@ -1270,11 +1293,11 @@ $red: #ff0000;
} }
td.el-table__cell { td.el-table__cell {
background-color: #ffffff; background-color: #ffffff;
border-bottom: 2px solid #f8f8f8; border-bottom: 1px dashed #ddd;
} }
th.el-table__cell { th.el-table__cell {
background-color: #f2f9f4; background-color: #f2f9f4;
border-bottom: 2px solid #f8f8f8; border-bottom: 1px dashed #ddd;
} }
.el-table__cell { .el-table__cell {
padding: 6px 0; padding: 6px 0;