1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-10 20:39:48 +08:00

Support Binary (#670)

* add services binary

* search for server image and use image service to view it

* add request Resource

* fix error and rename service

* rename service

Co-authored-by: Elsio Sanchez <elsiosanche@gmail.com>
This commit is contained in:
Elsio Sanchez 2021-03-21 19:19:07 -04:00 committed by GitHub
parent e9d1613b8a
commit 4401c1d77d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 91 additions and 1 deletions

View File

@ -0,0 +1,36 @@
/**
* Get entity with binary by identifier
* @param {string} tableName
* @param {string} recordUuid
*/
export function getResource({
uuid,
tableName
}) {
const { requestGetEntity } = require('@/api/ADempiere/persistence.js')
return requestGetEntity({
recordUuid: uuid,
tableName
})
}
/**
* Update an existing binary by id or uuid
* @param {string} tableName
* @param {string} recordUuid
* @param {object} binaryFile
*/
export function updateResource({
uuid,
tableName,
binaryFile
}) {
const { requestUpdateEntity } = require('@/api/ADempiere/persistence.js')
return requestUpdateEntity({
recordUuid: uuid,
tableName,
attributesList: binaryFile
})
}

View File

@ -4,6 +4,7 @@
action="https://jsonplaceholder.typicode.com/posts/" action="https://jsonplaceholder.typicode.com/posts/"
:show-file-list="false" :show-file-list="false"
:on-success="handleAvatarSuccess" :on-success="handleAvatarSuccess"
:on-change="handleChange"
:before-upload="beforeAvatarUpload" :before-upload="beforeAvatarUpload"
:disabled="isDisabled" :disabled="isDisabled"
:class="cssClassStyle" :class="cssClassStyle"
@ -15,10 +16,27 @@
<script> <script>
import fieldMixin from '@/components/ADempiere/Field/mixin/mixinField.js' import fieldMixin from '@/components/ADempiere/Field/mixin/mixinField.js'
import { getResource, updateResource } from '@/api/ADempiere/field/binary.js'
export default { export default {
name: 'FieldImage', name: 'FieldImage',
mixins: [fieldMixin], mixins: [fieldMixin],
props: {
// receives the property that is an object with all the attributes
binary: {
type: Array,
default: () => []
}
},
data() {
return {
valuesImage: [{
identifier: 'undefined',
value: '',
isLoaded: true
}]
}
},
computed: { computed: {
cssClassStyle() { cssClassStyle() {
let styleClass = ' custom-field-image ' let styleClass = ' custom-field-image '
@ -29,10 +47,46 @@ export default {
} }
}, },
methods: { methods: {
updateResource,
getResource,
handleChange(file, fileList) {
let message, type
this.binary.push({
columnName: this.metadata.columnName,
value: file
})
switch (file.status) {
case 'success':
message = 'succesful'
type = file.status
break
case 'ready':
message = 'loading'
type = 'loading'
break
case 'error':
message = file.status
type = file.status
break
}
this.$message({
type: type,
showClose: true,
message: this.$t('notifications.' + message)
})
updateResource({
uuid: this.metadata.recordUuid,
tableName: this.$route.params.tableName,
binaryFile: this.binary
})
},
handleAvatarSuccess(res, file) { handleAvatarSuccess(res, file) {
this.value = URL.createObjectURL(file.raw) this.value = URL.createObjectURL(file.raw)
// TODO: define one method to control change value
this.handleFieldChange({ value: this.value }) this.handleFieldChange({ value: this.value })
getResource({
uuid: this.metadata.recordUuid,
tableName: this.$route.params.tableName
})
}, },
beforeAvatarUpload(file) { beforeAvatarUpload(file) {
const isJPG = file.type === 'image/jpeg' const isJPG = file.type === 'image/jpeg'