优化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
+124 -10
View File
@@ -186,7 +186,7 @@
</div>
</div>
<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>
</div>
</div>
@@ -213,6 +213,14 @@ import files from './files/file'
export default {
name: 'UserInfo',
components: { fileEmpty, files },
props: {
saveWorkList: {
type: Object | undefined
},
isNew: {
type: Boolean
},
},
data() {
return {
addShow: false,
@@ -410,6 +418,57 @@ export default {
},
deep: 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: {
@@ -447,10 +506,60 @@ export default {
async upload_over() {},
// 保存
workSave() {
that.saveFlag = true
setTimeout(() => {
that.saveFlag = false
}, 1000)
let that = this
if (that.form.json_file === '' && that.$refs.files.filesList.length === 0) {
that.$message({
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() {
@@ -552,6 +661,7 @@ export default {
that.form.ass_task.push(task)
}
// csv文件处理
console.log(that.form.udf_file, that.soonList)
if (!that.form.udf_file && that.soonList.length > 0) {
that.soonList.forEach((item) => {
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 csv2 = that.soonList.map(item => item.val).join(',')
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(() => {
}).catch(() => {
@@ -722,10 +834,12 @@ export default {
//let flag = true; //校验结果
let first_line = this.result.split('\n')[0].replace('\r', '').split(',') //第一行
let second_line = this.result.split('\n')[1].replace('\r', '').split(',') //第二行
let i = 0
for (let item of first_line) {
that.$set(that.soonform, item, second_line[i])
i++
console.log(first_line, second_line)
for (let i = 0; i < first_line.length; i++) {
let index = that.soonList.findIndex(soon => soon.origin_name === first_line[i])
if(index > -1) {
that.soonList[index].val = second_line[i]
}
}
that.csvIsExist = true
}
@@ -1078,7 +1192,7 @@ export default {
font-weight: 500;
font-size: 16px;
color: #25aed9;
line-height: 30px;
line-height: 40px;
text-align: center;
margin-left: 30px;
}