|
@@ -47,7 +47,7 @@
|
|
|
:on-exceed="handleExceed"
|
|
|
:file-list="file"
|
|
|
>
|
|
|
- <el-button size="small" type="primary">Click to upload</el-button>
|
|
|
+ <el-button size="small" type="primary">选择图片</el-button>
|
|
|
<!-- <template #tip>
|
|
|
<div class="el-upload__tip">
|
|
|
jpg/png files with a size less than 500kb
|
|
@@ -66,7 +66,7 @@
|
|
|
</el-dialog>
|
|
|
</template>
|
|
|
<script>
|
|
|
-import { addPerson, addPersonPicture } from "@/utils/chenApi.js";
|
|
|
+import { addPerson, addPersonPicture, addPictureToPerson } from "@/utils/chenApi.js";
|
|
|
import { getFaceToken } from "@/utils/api.js";
|
|
|
export default {
|
|
|
data() {
|
|
@@ -131,14 +131,27 @@ export default {
|
|
|
const formData = new FormData();
|
|
|
formData.append("file", this.file[0]);
|
|
|
const { token } = await getFaceToken({});
|
|
|
- const pictureRes = await addPersonPicture(formData, token);
|
|
|
- console.log(pictureRes);
|
|
|
+ const { data } = await addPersonPicture(formData, token);
|
|
|
+ console.log(data);
|
|
|
+ if(data) {
|
|
|
+ let params = {
|
|
|
+ personId: res.data.data.id,
|
|
|
+ path: data
|
|
|
+ }
|
|
|
+ addPictureToPerson(params).then(res => {
|
|
|
+ if(res.code == 0) {
|
|
|
+ this.$message.success('新增档案成功!');
|
|
|
+ this.handleCancel();
|
|
|
+ this.$emit("reflash");
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
} catch (err) {
|
|
|
this.$message.error(`照片${this.form.id ? "修改" : "添加"}成功`);
|
|
|
}
|
|
|
- this.$message.success(`${this.form.id ? "修改" : "添加"}成功`);
|
|
|
- this.handleCancel();
|
|
|
- this.$emit("reflash");
|
|
|
+ // this.$message.success(`${this.form.id ? "修改" : "添加"}成功`);
|
|
|
+ // this.handleCancel();
|
|
|
+ // this.$emit("reflash");
|
|
|
} else {
|
|
|
this.$message.error(`${this.form.id ? "修改" : "添加"}失败`);
|
|
|
}
|
|
@@ -164,7 +177,18 @@ export default {
|
|
|
return this.$confirm(`取消上传${file.name} ?`);
|
|
|
},
|
|
|
handleSuccess(file) {
|
|
|
- this.file.push(file);
|
|
|
+ const isImg = file.raw.type === 'image/jpeg' || file.raw.type === 'image/png';
|
|
|
+ const isLt2M = file.size / 1024 / 1024 < 2;
|
|
|
+ if(!isLt2M) {
|
|
|
+ this.$message.error('上传头像图片大小不能超过 2MB!');
|
|
|
+ this.file = [];
|
|
|
+ }
|
|
|
+ if(!isImg) {
|
|
|
+ this.$message.error('上传头像图片只能是JPG或者png格式的图片!');
|
|
|
+ this.file = [];
|
|
|
+ } else {
|
|
|
+ this.file.push(file.raw);
|
|
|
+ }
|
|
|
},
|
|
|
},
|
|
|
};
|