Commit 69e184721c0d038ad5b11083b5ee505c5a0789d6
1 parent
084d379c
v1.9 员工头像不对问题
Showing
6 changed files
with
51 additions
and
38 deletions
src/components/owner/addOwner.vue
| @@ -197,10 +197,10 @@ export default { | @@ -197,10 +197,10 @@ export default { | ||
| 197 | const isLt2M = file.size / 1024 / 1024 < 2 | 197 | const isLt2M = file.size / 1024 / 1024 < 2 |
| 198 | 198 | ||
| 199 | if (!isJPG) { | 199 | if (!isJPG) { |
| 200 | - this.$message.error(this.$t('listOwner.upload.jpgOnly')) | 200 | + this.$message.error(this.$t('common.jpgOnly')) |
| 201 | } | 201 | } |
| 202 | if (!isLt2M) { | 202 | if (!isLt2M) { |
| 203 | - this.$message.error(this.$t('listOwner.upload.sizeLimit')) | 203 | + this.$message.error(this.$t('common.sizeLimit')) |
| 204 | } | 204 | } |
| 205 | return isJPG && isLt2M | 205 | return isJPG && isLt2M |
| 206 | }, | 206 | }, |
src/components/owner/editOwner.vue
| @@ -208,10 +208,10 @@ export default { | @@ -208,10 +208,10 @@ export default { | ||
| 208 | const isLt2M = file.size / 1024 / 1024 < 2 | 208 | const isLt2M = file.size / 1024 / 1024 < 2 |
| 209 | 209 | ||
| 210 | if (!isJPG) { | 210 | if (!isJPG) { |
| 211 | - this.$message.error(this.$t('listOwner.upload.jpgOnly')) | 211 | + this.$message.error(this.$t('common.jpgOnly')) |
| 212 | } | 212 | } |
| 213 | if (!isLt2M) { | 213 | if (!isLt2M) { |
| 214 | - this.$message.error(this.$t('listOwner.upload.sizeLimit')) | 214 | + this.$message.error(this.$t('common.sizeLimit')) |
| 215 | } | 215 | } |
| 216 | return isJPG && isLt2M | 216 | return isJPG && isLt2M |
| 217 | }, | 217 | }, |
src/components/staff/editStaff.vue
| @@ -30,16 +30,13 @@ | @@ -30,16 +30,13 @@ | ||
| 30 | </el-form-item> | 30 | </el-form-item> |
| 31 | </el-col> | 31 | </el-col> |
| 32 | <el-col :span="12" style="text-align: center"> | 32 | <el-col :span="12" style="text-align: center"> |
| 33 | - <el-image style="width: 200px; height: 200px" :src="editStaffInfo.photoUrl" fit="cover"> | ||
| 34 | - <div slot="error" class="image-slot"> | ||
| 35 | - <i class="el-icon-picture-outline"></i> | ||
| 36 | - </div> | ||
| 37 | - </el-image> | ||
| 38 | - <div style="margin-top: 20px"> | ||
| 39 | - <el-upload action="" :auto-upload="false" :show-file-list="false" :on-change="handlePhotoChange"> | ||
| 40 | - <el-button type="primary">{{ $t('staff.uploadPhoto') }}</el-button> | ||
| 41 | - </el-upload> | ||
| 42 | - </div> | 33 | + <el-image style="width: 200px; height: 150px; border: 1px dashed #ccc;" |
| 34 | + :src="editStaffInfo.photoUrl || '/img/noPhoto.jpg'" fit="cover" /> | ||
| 35 | + <el-upload class="mt-10" :show-file-list="false" :before-upload="beforeUpload" :http-request="uploadImage" action=""> | ||
| 36 | + <el-button size="small" type="primary"> | ||
| 37 | + {{ $t('common.upload') }} | ||
| 38 | + </el-button> | ||
| 39 | + </el-upload> | ||
| 43 | </el-col> | 40 | </el-col> |
| 44 | </el-row> | 41 | </el-row> |
| 45 | </el-form> | 42 | </el-form> |
| @@ -53,6 +50,8 @@ | @@ -53,6 +50,8 @@ | ||
| 53 | <script> | 50 | <script> |
| 54 | import { modifyStaff } from '@/api/staff/staffApi' | 51 | import { modifyStaff } from '@/api/staff/staffApi' |
| 55 | import { getDict } from '../../api/community/communityApi' | 52 | import { getDict } from '../../api/community/communityApi' |
| 53 | +import { uploadImage } from '@/api/owner/ownerApi' | ||
| 54 | + | ||
| 56 | 55 | ||
| 57 | export default { | 56 | export default { |
| 58 | name: 'EditStaff', | 57 | name: 'EditStaff', |
| @@ -95,7 +94,6 @@ export default { | @@ -95,7 +94,6 @@ export default { | ||
| 95 | this.editStaffInfo = { | 94 | this.editStaffInfo = { |
| 96 | ...val, | 95 | ...val, |
| 97 | username: val.name, | 96 | username: val.name, |
| 98 | - photoUrl: val.faceUrl || '/img/noPhoto.jpg' | ||
| 99 | } | 97 | } |
| 100 | } | 98 | } |
| 101 | } | 99 | } |
| @@ -103,11 +101,17 @@ export default { | @@ -103,11 +101,17 @@ export default { | ||
| 103 | }, | 101 | }, |
| 104 | methods: { | 102 | methods: { |
| 105 | open(row) { | 103 | open(row) { |
| 104 | + let _url = '/img/noPhoto.jpg' | ||
| 105 | + if(row.urls && row.urls.length > 0){ | ||
| 106 | + _url = row.urls[0] | ||
| 107 | + } | ||
| 106 | this.editStaffInfo = { | 108 | this.editStaffInfo = { |
| 107 | ...row, | 109 | ...row, |
| 108 | username: row.name, | 110 | username: row.name, |
| 109 | - photoUrl: row.faceUrl || '/img/noPhoto.jpg' | 111 | + photo: _url |
| 110 | } | 112 | } |
| 113 | + this.editStaffInfo.photoUrl = row.photoUrl || '/img/noPhoto.jpg' | ||
| 114 | + console.log(this.editStaffInfo.photoUrl) | ||
| 111 | this.getRelCd() | 115 | this.getRelCd() |
| 112 | this.visible = true | 116 | this.visible = true |
| 113 | 117 | ||
| @@ -120,21 +124,6 @@ export default { | @@ -120,21 +124,6 @@ export default { | ||
| 120 | handleClose() { | 124 | handleClose() { |
| 121 | this.visible = false | 125 | this.visible = false |
| 122 | }, | 126 | }, |
| 123 | - handlePhotoChange(file) { | ||
| 124 | - if (file.size > 2 * 1024 * 1024) { | ||
| 125 | - this.$message.error(this.$t('staff.photoSizeLimit')) | ||
| 126 | - return false | ||
| 127 | - } | ||
| 128 | - | ||
| 129 | - const reader = new FileReader() | ||
| 130 | - reader.onload = (e) => { | ||
| 131 | - this.editStaffInfo.photoUrl = e.target.result | ||
| 132 | - // Here you would typically upload the file to server | ||
| 133 | - // and set editStaffInfo.photo to the returned file ID | ||
| 134 | - this.editStaffInfo.photo = file.uid // Temporary, replace with actual file ID | ||
| 135 | - } | ||
| 136 | - reader.readAsDataURL(file.raw) | ||
| 137 | - }, | ||
| 138 | validateForm() { | 127 | validateForm() { |
| 139 | if (!this.editStaffInfo.username) { | 128 | if (!this.editStaffInfo.username) { |
| 140 | this.$message.error(this.$t('staff.requiredName')) | 129 | this.$message.error(this.$t('staff.requiredName')) |
| @@ -175,7 +164,29 @@ export default { | @@ -175,7 +164,29 @@ export default { | ||
| 175 | } finally { | 164 | } finally { |
| 176 | this.loading = false | 165 | this.loading = false |
| 177 | } | 166 | } |
| 178 | - } | 167 | + }, |
| 168 | + beforeUpload(file) { | ||
| 169 | + const isJPG = file.type === 'image/jpeg' | ||
| 170 | + const isLt2M = file.size / 1024 / 1024 < 2 | ||
| 171 | + | ||
| 172 | + if (!isJPG) { | ||
| 173 | + this.$message.error(this.$t('common.jpgOnly')) | ||
| 174 | + } | ||
| 175 | + if (!isLt2M) { | ||
| 176 | + this.$message.error(this.$t('common.sizeLimit')) | ||
| 177 | + } | ||
| 178 | + return isJPG && isLt2M | ||
| 179 | + }, | ||
| 180 | + async uploadImage({ file }) { | ||
| 181 | + try { | ||
| 182 | + const res = await uploadImage({ file }) | ||
| 183 | + this.editStaffInfo.photo = res.fileId | ||
| 184 | + this.editStaffInfo.photoUrl = res.url | ||
| 185 | + this.$forceUpdate() | ||
| 186 | + } catch (error) { | ||
| 187 | + this.$message.error(this.$t('listOwner.upload.failed')) | ||
| 188 | + } | ||
| 189 | + }, | ||
| 179 | } | 190 | } |
| 180 | } | 191 | } |
| 181 | </script> | 192 | </script> |
src/i18n/commonLang.js
| @@ -65,7 +65,8 @@ export const messages = { | @@ -65,7 +65,8 @@ export const messages = { | ||
| 65 | viewDetail:'View Detail', | 65 | viewDetail:'View Detail', |
| 66 | yuan:'yuan', | 66 | yuan:'yuan', |
| 67 | process:'Process', | 67 | process:'Process', |
| 68 | - | 68 | + jpgOnly:'Only JPG files are allowed', |
| 69 | + sizeLimit:'File size must be less than 2MB', | ||
| 69 | } | 70 | } |
| 70 | }, | 71 | }, |
| 71 | zh: { | 72 | zh: { |
| @@ -134,7 +135,8 @@ export const messages = { | @@ -134,7 +135,8 @@ export const messages = { | ||
| 134 | viewDetail:'查看详情', | 135 | viewDetail:'查看详情', |
| 135 | yuan:'元', | 136 | yuan:'元', |
| 136 | process:'处理', | 137 | process:'处理', |
| 137 | - | 138 | + jpgOnly:'只允许上传JPG文件', |
| 139 | + sizeLimit:'文件大小必须小于2MB', | ||
| 138 | } | 140 | } |
| 139 | } | 141 | } |
| 140 | } | 142 | } |
| 141 | \ No newline at end of file | 143 | \ No newline at end of file |
src/views/org/orgList.vue
| @@ -29,7 +29,7 @@ | @@ -29,7 +29,7 @@ | ||
| 29 | <el-table-column prop="address" :label="$t('org.address')" align="center" /> | 29 | <el-table-column prop="address" :label="$t('org.address')" align="center" /> |
| 30 | <el-table-column prop="sex" :label="$t('org.gender')" align="center"> | 30 | <el-table-column prop="sex" :label="$t('org.gender')" align="center"> |
| 31 | <template #default="{ row }"> | 31 | <template #default="{ row }"> |
| 32 | - {{ row.sex === 0 ? '男' : '女' }} | 32 | + {{ row.sex == 0 ? '男' : '女' }} |
| 33 | </template> | 33 | </template> |
| 34 | </el-table-column> | 34 | </el-table-column> |
| 35 | <el-table-column :label="$t('org.operation')" align="center"> | 35 | <el-table-column :label="$t('org.operation')" align="center"> |
src/views/staff/staffDetailList.vue
| @@ -12,7 +12,7 @@ | @@ -12,7 +12,7 @@ | ||
| 12 | <div class="staff-info"> | 12 | <div class="staff-info"> |
| 13 | <el-row :gutter="20"> | 13 | <el-row :gutter="20"> |
| 14 | <el-col :span="4"> | 14 | <el-col :span="4"> |
| 15 | - <el-image style="width: 120px; height: 140px; border-radius: 4px;" :src="staffDetailInfo.photo" | 15 | + <el-image style="width: 120px; height: 140px; border-radius: 4px;" :src="staffDetailInfo.photoUrl" |
| 16 | fit="cover" @error="errorLoadImg"> | 16 | fit="cover" @error="errorLoadImg"> |
| 17 | </el-image> | 17 | </el-image> |
| 18 | </el-col> | 18 | </el-col> |
| @@ -143,7 +143,7 @@ export default { | @@ -143,7 +143,7 @@ export default { | ||
| 143 | this.$router.go(-1) | 143 | this.$router.go(-1) |
| 144 | }, | 144 | }, |
| 145 | errorLoadImg() { | 145 | errorLoadImg() { |
| 146 | - this.staffDetailInfo.photo = "/img/noPhoto.jpg" | 146 | + this.staffDetailInfo.photoUrl = "/img/noPhoto.jpg" |
| 147 | }, | 147 | }, |
| 148 | async loadStaffDetail() { | 148 | async loadStaffDetail() { |
| 149 | try { | 149 | try { |
| @@ -155,7 +155,7 @@ export default { | @@ -155,7 +155,7 @@ export default { | ||
| 155 | const res = await getStaffDetail(params) | 155 | const res = await getStaffDetail(params) |
| 156 | if ( res.staffs.length > 0) { | 156 | if ( res.staffs.length > 0) { |
| 157 | Object.assign(this.staffDetailInfo, res.staffs[0]) | 157 | Object.assign(this.staffDetailInfo, res.staffs[0]) |
| 158 | - this.staffDetailInfo.photo = res.staffs[0].faceUrl | 158 | + this.staffDetailInfo.photoUrl = res.staffs[0].photoUrl |
| 159 | } | 159 | } |
| 160 | } catch (error) { | 160 | } catch (error) { |
| 161 | this.$message.error(this.$t('staffDetailInfo.fetchError')) | 161 | this.$message.error(this.$t('staffDetailInfo.fetchError')) |