Detect type automatically when uploading texture

This commit is contained in:
Pig Fang 2019-05-04 17:09:44 +08:00
parent 85eefad0b1
commit 7b8b318402
6 changed files with 27 additions and 1 deletions

View File

@ -101,6 +101,7 @@
<script> <script>
import Vue from 'vue' import Vue from 'vue'
import FileUpload from 'vue-upload-component' import FileUpload from 'vue-upload-component'
import { isSlimSkin } from 'skinview3d'
import 'element-ui/lib/theme-chalk/radio.css' import 'element-ui/lib/theme-chalk/radio.css'
import Radio from 'element-ui/lib/radio' import Radio from 'element-ui/lib/radio'
@ -188,7 +189,10 @@ export default {
const image = new Image() const image = new Image()
image.src = this.texture image.src = this.texture
image.onload = () => (this.width2d = image.width > 400 ? 400 : image.width) image.onload = () => {
this.width2d = image.width > 400 ? 400 : image.width
this.type = isSlimSkin(image) ? 'alex' : 'steve'
}
}, },
remove() { remove() {
this.$refs.upload.clear() this.$refs.upload.clear()

View File

@ -49,3 +49,7 @@ export function createOrbitControls() {}
export const WalkingAnimation = { paused: false } export const WalkingAnimation = { paused: false }
export const RunningAnimation = { paused: false } export const RunningAnimation = { paused: false }
export const RotatingAnimation = { paused: false } export const RotatingAnimation = { paused: false }
export function isSlimSkin() {
return false
}

View File

@ -5,6 +5,7 @@ import Vue from 'vue'
import { import {
Button, Button,
Input, Input,
Radio,
Switch, Switch,
} from 'element-ui' } from 'element-ui'
@ -52,6 +53,7 @@ Vue.prototype.$http = {
Vue.use(Button) Vue.use(Button)
Vue.use(Input) Vue.use(Input)
Vue.use(Radio)
Vue.use(Switch) Vue.use(Switch)
Vue.prototype.$message = { Vue.prototype.$message = {
info: jest.fn(), info: jest.fn(),

View File

@ -1,6 +1,8 @@
/* eslint-disable accessor-pairs */ /* eslint-disable accessor-pairs */
import Vue from 'vue' import Vue from 'vue'
import { mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import { Radio } from 'element-ui'
import * as skinview3d from 'skinview3d'
import Upload from '@/views/skinlib/Upload.vue' import Upload from '@/views/skinlib/Upload.vue'
import { flushPromises } from '../../utils' import { flushPromises } from '../../utils'
@ -83,6 +85,9 @@ test('process input file', () => {
set: fn => fn(), set: fn => fn(),
}) })
}) })
jest.spyOn(skinview3d, 'isSlimSkin')
.mockReturnValueOnce(true)
.mockReturnValue(false)
const blob = new Blob() const blob = new Blob()
type Component = Vue & { type Component = Vue & {
name: string name: string
@ -92,15 +97,18 @@ test('process input file', () => {
const wrapper = mount<Component>(Upload, { const wrapper = mount<Component>(Upload, {
stubs: ['file-upload'], stubs: ['file-upload'],
}) })
const radioes = wrapper.findAll(Radio)
wrapper.vm.inputFile() wrapper.vm.inputFile()
expect(wrapper.vm.name).toBe('') expect(wrapper.vm.name).toBe('')
wrapper.vm.inputFile({ file: blob, name: '123.png' }) wrapper.vm.inputFile({ file: blob, name: '123.png' })
expect(wrapper.vm.name).toBe('123') expect(wrapper.vm.name).toBe('123')
expect(radioes.at(1).classes()).toContain('is-checked')
wrapper.vm.inputFile({ file: blob, name: '456.png' }) wrapper.vm.inputFile({ file: blob, name: '456.png' })
expect(wrapper.vm.name).toBe('123') expect(wrapper.vm.name).toBe('123')
expect(radioes.at(0).classes()).toContain('is-checked')
wrapper.setData({ name: '' }) wrapper.setData({ name: '' })
wrapper.vm.inputFile({ file: blob, name: '789' }) wrapper.vm.inputFile({ file: blob, name: '789' })

View File

@ -1,3 +1,7 @@
## Added
- Detect type automatically when uploading texture.
## Fixed ## Fixed
- Fixed dropdown menu of skin library for mobile users. - Fixed dropdown menu of skin library for mobile users.

View File

@ -1,3 +1,7 @@
## 新增
- 上传皮肤时自动检测类型
## 修复 ## 修复
- 修复移动端下皮肤库下拉菜单失效的问题 - 修复移动端下皮肤库下拉菜单失效的问题