Commit eb0e4ede authored by YIyiyi's avatar YIyiyi

pref:修改工作人员照片上传

parent ae4ebbc8
...@@ -522,7 +522,8 @@ export default { ...@@ -522,7 +522,8 @@ export default {
/deep/.ant-card { /deep/.ant-card {
width: 100% !important; width: 100% !important;
} }
.svg-box { .svg-box,
/deep/.ant-upload-list-item-thumbnail {
background-color: #54788c; background-color: #54788c;
} }
/deep/.ant-modal-content { /deep/.ant-modal-content {
......
...@@ -653,11 +653,11 @@ export default { ...@@ -653,11 +653,11 @@ export default {
if (!isJpgOrPng) { if (!isJpgOrPng) {
this.$message.error("请上传jpeg或者png图片!"); this.$message.error("请上传jpeg或者png图片!");
} }
const isLt2M = file.size / 1024 / 1024 < 2; const isLt10M = file.size / 1024 / 1024 < 10;
if (!isLt2M) { if (!isLt10M) {
this.$message.error("图片大小不能超过2MB!"); this.$message.error("图片大小不能超过10MB!");
} }
return isJpgOrPng && isLt2M; return isJpgOrPng && isLt10M;
}, },
// 上传图片 // 上传图片
handleChange({ fileList }) { handleChange({ fileList }) {
......
...@@ -194,6 +194,24 @@ ...@@ -194,6 +194,24 @@
> >
<div class="person_image"> <div class="person_image">
<a-upload <a-upload
name="file"
list-type="picture-card"
class="avatar-uploader"
:file-list="fileList"
:before-upload="beforeUpload"
:action="api + 'base/file/commonupload'"
:accept="accept"
@change="handleChange"
@preview="handlePreview"
>
<div v-if="fileList.length < 1">
<a-icon type="plus" />
<div class="ant-upload-text">
添加照片
</div>
</div>
</a-upload>
<!-- <a-upload
name="file" name="file"
list-type="picture-card" list-type="picture-card"
class="avatar-uploader" class="avatar-uploader"
...@@ -213,7 +231,7 @@ ...@@ -213,7 +231,7 @@
<a-icon :type="loading ? 'loading' : 'plus'" /> <a-icon :type="loading ? 'loading' : 'plus'" />
<div class="ant-upload-text">添加照片</div> <div class="ant-upload-text">添加照片</div>
</div> </div>
</a-upload> </a-upload> -->
<span <span
>请上传jpg、png、jpeg格式图片 <br /> >请上传jpg、png、jpeg格式图片 <br />
建议尺寸:250px*350px</span 建议尺寸:250px*350px</span
...@@ -312,12 +330,18 @@ ...@@ -312,12 +330,18 @@
<a-button @click="handleReset">重置</a-button> <a-button @click="handleReset">重置</a-button>
<a-button type="primary" @click="hideModal">确定</a-button> <a-button type="primary" @click="hideModal">确定</a-button>
</div> </div>
<!-- 预览 -->
<PrevieModal
:previewData="previewData"
:previewVisible.sync="previewVisible"
></PrevieModal>
</a-modal> </a-modal>
</template> </template>
<script> <script>
import { getWindowList, saveWorkman } from "@/services/dept"; import { getWindowList, saveWorkman } from "@/services/dept";
import { modelList } from "@/services/basicsetFun"; import { modelList } from "@/services/basicsetFun";
import PrevieModal from "@/components/PrevieModal.vue";
// import { changePhone, changeLandline } from "@/utils/validate"; // import { changePhone, changeLandline } from "@/utils/validate";
export default { export default {
props: { props: {
...@@ -346,6 +370,9 @@ export default { ...@@ -346,6 +370,9 @@ export default {
}, },
}, },
}, },
components: {
PrevieModal,
},
data() { data() {
const checkIdCard = (rule, value, callback) => { const checkIdCard = (rule, value, callback) => {
if (!value) { if (!value) {
...@@ -363,6 +390,9 @@ export default { ...@@ -363,6 +390,9 @@ export default {
return { return {
api: process.env.VUE_APP_API_BASE_URL + "/", api: process.env.VUE_APP_API_BASE_URL + "/",
accept: "image/jpeg,image/png", // 上传类型 accept: "image/jpeg,image/png", // 上传类型
previewData: {}, // 预览
previewVisible: false,
fileList: [],
loading: false, loading: false,
imageUrl: "", imageUrl: "",
labelCol: { span: 5 }, labelCol: { span: 5 },
...@@ -485,6 +515,17 @@ export default { ...@@ -485,6 +515,17 @@ export default {
this.form = { ...data }; this.form = { ...data };
this.form.loginName && this.$delete(this.form, "loginName"); this.form.loginName && this.$delete(this.form, "loginName");
this.form.loginPwd && this.$delete(this.form, "loginPwd"); this.form.loginPwd && this.$delete(this.form, "loginPwd");
if (this.form.photoPath) {
this.fileList = [
{
uid: -1,
status: "done",
name: this.form.photoPath,
url: this.api + this.form.photoPath,
url2: this.form.photoPath,
},
];
}
// this.editWindow(data.deptId); // this.editWindow(data.deptId);
}, },
// 关闭对话框 // 关闭对话框
...@@ -498,13 +539,29 @@ export default { ...@@ -498,13 +539,29 @@ export default {
this.$refs.formData.resetFields(); this.$refs.formData.resetFields();
}, },
// 照片上传 // 照片上传
handleChange({ file }) { handleChange({ fileList }) {
this.loading = true; this.fileList = [...fileList].slice(-1);
if (file.status == "done") { this.fileList = this.fileList.map((v) => {
this.form.photoPath = file.response.url; if (v.response) {
this.loading = false; v.url2 = v.response.url;
v.url = this.api + v.response.url;
}
return v;
});
if (this.fileList[0]) {
this.form.photoPath = this.fileList[0].url2;
} else {
this.form.photoPath = "";
} }
}, },
// 预览
handlePreview(info) {
this.previewData = {
type: "img",
url: info.url,
};
this.previewVisible = true;
},
// 照片大小格式限制 // 照片大小格式限制
beforeUpload(file) { beforeUpload(file) {
const isJpgOrPng = const isJpgOrPng =
...@@ -524,10 +581,17 @@ export default { ...@@ -524,10 +581,17 @@ export default {
<style lang="less" scoped> <style lang="less" scoped>
/deep/.ant-upload, /deep/.ant-upload,
.avatar-uploader { /deep/.avatar-uploader {
width: 120px; width: 120px;
height: 170px; height: 170px;
margin-right: 20px; margin-right: 20px;
.ant-upload-list-item {
width: 120px;
height: 170px;
}
.ant-upload-list-item-thumbnail {
object-fit: cover;
}
} }
.person_image { .person_image {
display: flex; display: flex;
...@@ -598,4 +662,4 @@ export default { ...@@ -598,4 +662,4 @@ export default {
/deep/.ant-col-2 { /deep/.ant-col-2 {
width: 8.33333333% !important; width: 8.33333333% !important;
} }
</style> </style>
\ No newline at end of file
...@@ -203,14 +203,20 @@ ...@@ -203,14 +203,20 @@
name="file" name="file"
list-type="picture-card" list-type="picture-card"
class="avatar-uploader" class="avatar-uploader"
:show-upload-list="false" :file-list="fileList"
:before-upload="beforeUpload" :before-upload="beforeUpload"
:action="api + 'base/file/commonupload'" :action="api + 'base/file/commonupload'"
:accept="accept" :accept="accept"
@change="handleChange" @change="handleChange"
:remove="handleRemove" @preview="handlePreview"
> >
<img <div v-if="fileList.length < 1">
<a-icon type="plus" />
<div class="ant-upload-text">
添加照片
</div>
</div>
<!-- <img
v-if="form.photoPath" v-if="form.photoPath"
class="avatar" class="avatar"
:src="api + form.photoPath" :src="api + form.photoPath"
...@@ -219,7 +225,7 @@ ...@@ -219,7 +225,7 @@
<div v-else> <div v-else>
<a-icon :type="loading ? 'loading' : 'plus'" /> <a-icon :type="loading ? 'loading' : 'plus'" />
<div class="ant-upload-text">添加照片</div> <div class="ant-upload-text">添加照片</div>
</div> </div> -->
</a-upload> </a-upload>
<span <span
>请上传jpg、png、jpeg格式图片 <br /> >请上传jpg、png、jpeg格式图片 <br />
...@@ -362,6 +368,11 @@ ...@@ -362,6 +368,11 @@
<a-button @click="handleReset">重置</a-button> <a-button @click="handleReset">重置</a-button>
<a-button type="primary" @click="hideModal">确定</a-button> <a-button type="primary" @click="hideModal">确定</a-button>
</div> </div>
<!-- 预览 -->
<PrevieModal
:previewData="previewData"
:previewVisible.sync="previewVisible"
></PrevieModal>
</a-modal> </a-modal>
</template> </template>
...@@ -369,6 +380,7 @@ ...@@ -369,6 +380,7 @@
import { changeAccount, changePassWord } from "@/utils/validate"; import { changeAccount, changePassWord } from "@/utils/validate";
import { getWindowList, saveWorkman } from "@/services/dept"; import { getWindowList, saveWorkman } from "@/services/dept";
import { modelList } from "@/services/basicsetFun"; import { modelList } from "@/services/basicsetFun";
import PrevieModal from "@/components/PrevieModal.vue";
// import { changePhone, changeLandline } from "@/utils/validate"; // import { changePhone, changeLandline } from "@/utils/validate";
import local from "@/utils/local"; import local from "@/utils/local";
export default { export default {
...@@ -398,6 +410,9 @@ export default { ...@@ -398,6 +410,9 @@ export default {
}, },
}, },
}, },
components: {
PrevieModal,
},
data() { data() {
const checkIdCard = (rule, value, callback) => { const checkIdCard = (rule, value, callback) => {
if (!value) { if (!value) {
...@@ -415,6 +430,9 @@ export default { ...@@ -415,6 +430,9 @@ export default {
return { return {
api: process.env.VUE_APP_API_BASE_URL + "/", api: process.env.VUE_APP_API_BASE_URL + "/",
accept: "image/jpeg,image/png", // 上传类型 accept: "image/jpeg,image/png", // 上传类型
previewData: {}, // 预览
previewVisible: false,
fileList: [],
loading: false, loading: false,
imageUrl: "", imageUrl: "",
labelCol: { span: 5 }, labelCol: { span: 5 },
...@@ -551,6 +569,17 @@ export default { ...@@ -551,6 +569,17 @@ export default {
onEdit(data) { onEdit(data) {
this.form = { ...data }; this.form = { ...data };
this.editWindow(data.deptId); this.editWindow(data.deptId);
if (this.form.photoPath) {
this.fileList = [
{
uid: -1,
status: "done",
name: this.form.photoPath,
url: this.api + this.form.photoPath,
url2: this.form.photoPath,
},
];
}
}, },
// 关闭对话框 // 关闭对话框
handleClose() { handleClose() {
...@@ -558,26 +587,31 @@ export default { ...@@ -558,26 +587,31 @@ export default {
this.loading = false; this.loading = false;
this.Visible = false; this.Visible = false;
}, },
// 照片上传 // 照片上传
handleChange({ file }) { handleChange({ fileList }) {
this.loading = true; this.fileList = [...fileList].slice(-1);
if (file.status == "done") { this.fileList = this.fileList.map((v) => {
this.form.photoPath = file.response.url; if (v.response) {
this.loading = false; v.url2 = v.response.url;
v.url = this.api + v.response.url;
}
return v;
});
if (this.fileList[0]) {
this.form.photoPath = this.fileList[0].url2;
} else {
this.form.photoPath = "";
} }
}, },
handleRemove() {}, // 预览
// async uploadImg(info) { handlePreview(info) {
// this.loading = true; this.previewData = {
// const formData = new FormData(); type: "img",
// formData.append("file", info.file); url: info.url,
// let res = await uploadFile(formData); };
// let { code, url } = res.data; this.previewVisible = true;
// if (code === 1) { },
// this.form.photoPath = url;
// this.loading = false;
// }
// },
// 照片大小格式限制 // 照片大小格式限制
beforeUpload(file) { beforeUpload(file) {
const isJpgOrPng = const isJpgOrPng =
...@@ -597,11 +631,19 @@ export default { ...@@ -597,11 +631,19 @@ export default {
<style lang="less" scoped> <style lang="less" scoped>
/deep/.ant-upload, /deep/.ant-upload,
.avatar-uploader { /deep/.avatar-uploader {
width: 120px; width: 120px;
height: 170px; height: 170px;
margin-right: 20px; margin-right: 20px;
.ant-upload-list-item {
width: 120px;
height: 170px;
}
.ant-upload-list-item-thumbnail {
object-fit: cover;
}
} }
.person_image { .person_image {
display: flex; display: flex;
align-items: center; align-items: center;
...@@ -609,11 +651,11 @@ export default { ...@@ -609,11 +651,11 @@ export default {
color: #ccc; color: #ccc;
} }
} }
.avatar { .avatar,
width: 120px; /deep/.ant-upload-list-item-thumbnail {
height: 170px;
object-fit: cover; object-fit: cover;
} }
/deep/.ant-form-item { /deep/.ant-form-item {
margin-bottom: 15px; margin-bottom: 15px;
} }
...@@ -671,4 +713,4 @@ export default { ...@@ -671,4 +713,4 @@ export default {
/deep/.ant-col-2 { /deep/.ant-col-2 {
width: 8.33333333% !important; width: 8.33333333% !important;
} }
</style> </style>
\ No newline at end of file
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