Browse Source

完善

test
zhangyuan 3 years ago
parent
commit
93b811dc3d
  1. 182
      src/views/modules/worklog/icworklog-add-or-update.vue
  2. 130
      src/views/modules/worklog/upload-image.vue

182
src/views/modules/worklog/icworklog-add-or-update.vue

@ -47,34 +47,26 @@
<el-form-item label="备注" prop="remark">
<el-input type="textarea" v-model="dataForm.remark" placeholder="备注"></el-input>
</el-form-item>
<el-form-item label="合同附件" prop="fileList" label-width="140px">
<template>
<upload-image :defaultFileList="dataForm.fileList" :limit="6" @change="onChangeFileList"></upload-image>
</template>
<el-form-item class="block"
label="附件"
label-width="150px"
prop="attach">
<el-upload class="upload-demo"
:action="uploadUlr"
accept=".doc,.pdf,.xls,.docx,.xlsx,.jpg,.png,.jpeg,.bmp,.mp4,.wma,.m4a,.mp3"
:on-success="handleFileSuccess"
:on-remove="handleFileRemove"
:on-preview="handleFileDownload"
:limit="3"
:before-upload="beforeUpload"
:file-list="dataForm.fileList">
<el-button size="small"
:disabled="dataForm.fileList.length===3"
type="primary">点击上传</el-button>
<div slot="tip"
class="el-upload__tip">支持图片wordpdf</div>
</el-upload>
</el-form-item>
<!-- <el-form-item-->
<!-- label="图片/附件"-->
<!-- label-width="150px"-->
<!-- style="display: block"-->
<!-- prop="fileList"-->
<!-- >-->
<!-- <el-upload-->
<!-- class="avatar-uploader"-->
<!-- :action="uploadUrl"-->
<!-- :data="{ customerId: customerId }"-->
<!-- :show-file-list="true"-->
<!-- :file-list="dataForm.fileList"-->
<!-- :on-preview="handleImgPreview"-->
<!-- :on-success="handleImgSuccess"-->
<!-- :on-remove="handleImgRemove"-->
<!-- :on-exceed="handleImgExceed"-->
<!-- :before-upload="beforeImgUpload"-->
<!-- :limit="3"-->
<!-- >-->
<!-- <i class="el-icon-plus avatar-uploader-icon"></i>-->
<!-- <span style="color: #999"> 点击上传支持图片wordpdf格式</span>-->
<!-- </el-upload>-->
<!-- </el-form-item>-->
</el-form>
<template slot="footer">
<el-button @click="visible = false">{{ $t('cancel') }}</el-button>
@ -86,13 +78,11 @@
<script>
import debounce from 'lodash/debounce'
import { requestPost } from "@/js/dai/request"
import UploadImage from './upload-image.vue'
export default {
data () {
return {
visible: false,
uploadUrl: window.SITE_CONFIG["apiURL"] + "/oss/file/uploadqrcodeV2",
customerId: localStorage.getItem("customerId"),
uploadUlr: window.SITE_CONFIG['apiURL'] + '/oss/file/uploadvariedfile',
logTypeArr: [],
optionsG: [],
dataForm: {
@ -117,9 +107,6 @@ export default {
}
}
},
components: {
UploadImage
},
created () {
this.getGridList()
this.getCategrayList()
@ -209,94 +196,75 @@ export default {
return this.$message.error('网络错误')
})
},
onChangeFileList (e, rowIndex=0) {
console.log('onChangeFileList', e)
if (e.length > 0) {
this.dataForm.fileList = []
e.forEach(item => {
let ob = {
fileType: '0',
fileUrl: item.response.data.url
}
this.dataForm.fileList.push(ob)
})
beforeUpload (file) {
const array = file.name.split('.')
const extension = array[array.length - 1]
const formatarray = ['jpg', 'png', 'jpeg', 'bmp', 'mp4', 'wma', 'm4a', 'mp3', 'doc', 'docx', 'xls', 'xlsx', 'pdf']
if (formatarray.indexOf(extension) === -1) {
this.$message.error('只支持图片、word、pdf')
return false
}
},
beforeImgUpload(file) {
console.log(file);
const isLt1M = file.size / 1024 / 1024 < 10;
const srcType = file.type;
const format = file.name.split(".").pop();
if (!isLt1M) {
this.$message.error("上传文件大小不能超过 10MB!");
return false;
}
if (
srcType.indexOf("image") == -1 &&
srcType.indexOf("video") == -1 &&
["doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"].indexOf(format) ==
-1
) {
this.$message.error("仅限图片、word和pdf文件!");
return false;
handleFileRemove (file) {
if (file && file.status === "success") {
this.dataForm.fileList.splice(this.dataForm.fileList.findIndex(item => item.uid === file.uid), 1)
}
return true;
},
handleImgSuccess(res, file, fileList) {
console.log("handleImgSuccess", file);
if (res.code === 0 && res.msg === "success") {
let format = file.name.split(".").pop();
let srcType = file.raw.type;
let type = "file";
console.log("==============================srcType: ", srcType);
if (srcType.indexOf("image") != -1) {
type = "image";
} else if (srcType.indexOf("video") != -1) {
type = "video";
handleFileSuccess (res, file) {
if (res.code === 0 && res.msg === 'success') {
const array = file.name.split('.')
const fileType = array[array.length - 1]
const picArray = ['jpg', 'png', 'jpeg', 'bmp']
const videoarray = ['mp4', 'wma', 'm4a']
const docArray = ['doc', 'docx', 'xls', 'xlsx', 'pdf']
const mp3Array = ['mp3']
if (picArray.indexOf(fileType) > -1) {
file.attachmentFormat = 'image'
} else if (videoarray.indexOf(fileType) > -1) {
file.attachmentFormat = 'video'
} else if (docArray.indexOf(fileType) > -1) {
file.attachmentFormat = 'doc'
} else if (mp3Array.indexOf(fileType) > -1) {
file.attachmentFormat = 'voice'
}
this.dataForm.fileList.push({
format,
name: file.name,
size: file.size,
type,
url: res.data.url,
});
console.log(this.dataForm.fileList);
} else {
this.$message.error(res.msg);
}
},
handleImgPreview(file) {
console.log(file);
window.open(file.url || file.response.data.url);
},
file.url = res.data.url
file.type = fileType
handleImgRemove(file) {
console.log("handleImgRemove", file);
if (file.response) {
let index = this.dataForm.fileList.findIndex(
(item) => item.url == file.response.data.url
);
this.dataForm.fileList.splice(index, 1);
} else if (file.url) {
let index = this.dataForm.fileList.findIndex(
(item) => item.url == file.url
);
this.dataForm.fileList.splice(index, 1);
}
file.fileName = file.name
file.fileType = file.type
file.url = file.url
this.dataForm.fileList.push(file)
console.log(this.dataForm.fileList)
} else this.$message.error(res.msg)
},
//
handleFileDownload (file) {
var a = document.createElement('a');
var event = new MouseEvent('click');
a.download = file.name;
console.log(a)
a.href = file.url;
a.dispatchEvent(event);
handleImgExceed() {
this.$message({
type: "warning",
message: "文件数量最多不超过三个",
});
},
//
dataFormSubmitHandle: debounce(function () {
if (this.dataForm.content.length < 70) {
return this.$message.error("内容不能少于70字")
}
this.$refs['dataForm'].validate((valid) => {
if (!valid) {
return false

130
src/views/modules/worklog/upload-image.vue

@ -1,130 +0,0 @@
<template>
<div class="upload-image">
<el-upload list-type="picture-card"
:action="uploadUrl"
:data="{ customerId: customerId }"
:file-list="fileList"
:limit="limit"
:on-success="(res, file) => handleImgSuccess(res, file)"
:on-error="(res, file) => handleImgError(res, file)"
:on-remove="(res) => handleImgRemove(res)"
:on-exceed="(res) => handleImgExceed(res)"
:before-upload="(file) => beforeImgUpload(file)">
<i slot="default" class="el-icon-plus"></i>
<div slot="file" slot-scope="{file}">
<img class="el-upload-list__item-thumbnail" :src="file.url" alt="">
<span class="el-upload-list__item-actions">
<span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
<i class="el-icon-zoom-in"></i>
</span>
<span v-if="!disabled" class="el-upload-list__item-delete" @click="handleRemove(file)">
<i class="el-icon-delete"></i>
</span>
</span>
</div>
</el-upload>
<el-dialog :visible.sync="dialogVisible">
<img width="100%" :src="dialogImageUrl" alt="">
</el-dialog>
</div>
</template>
<script>
export default {
props: {
limit: {
type: Number,
default: 3
},
rowIndex: {
type: Number,
default: 0
},
defaultFileList: {
type: Array
}
},
watch: {
defaultFileList: {
handler (newVal) {
newVal.forEach(item => {
item.url = item.fileUrl
})
this.fileList = newVal
},
deep: true,
immediate: true
}
},
data () {
return {
dialogImageUrl: '',
dialogVisible: false,
disabled: false,
uploadUrl: `${window.SITE_CONFIG['apiURL']}/oss/file/uploadqrcodeV2`,
customerId: localStorage.getItem("customerId"),
fileList: [],
imageUrls: []
}
},
created() {
console.log('xxxxxx', this.rowIndex)
},
methods: {
handleRemove(file) {
const delFile = file.url
this.fileList.forEach((item, key) => {
if (delFile == item.url) {
this.fileList.splice(key, 1)
}
})
},
handlePictureCardPreview(file) {
this.dialogImageUrl = file.url
this.dialogVisible = true
},
beforeImgUpload(file) {
// console.log(file)
},
handleImgExceed(res) {
console.log(res)
this.$message({
type: "warning",
message: `文件数量最多不超过${this.limit}`,
})
},
handleImgRemove(file) {
console.log("handleImgRemove", file)
},
handleImgSuccess(res, file) {
// console.log("handleImgSuccess", res, file)
if (res.code === 0 && res.msg === "success") {
this.fileList.push(file)
this.$emit('change', this.fileList, this.rowIndex)
} else {
this.$message.error(res.msg)
}
},
handleImgError(res, file) {
console.log(res)
},
}
}
</script>
<style lang="scss" scoped>
.upload-image {
// min-width: 120px;
// height: 80px;
}
/deep/ .el-upload--picture-card {
width: 60px;
height: 60px;
line-height: 70px;
}
/deep/ .el-upload-list--picture-card .el-upload-list__item {
width: 60px;
height: 60px;
}
</style>
Loading…
Cancel
Save