mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
Merge branch 'master' into feature/unit_test
This commit is contained in:
commit
d7c4c73edb
@ -24,7 +24,8 @@ module.exports = {
|
|||||||
navigator: false,
|
navigator: false,
|
||||||
window: false,
|
window: false,
|
||||||
require: true,
|
require: true,
|
||||||
FileReader: true
|
FileReader: true,
|
||||||
|
File: true
|
||||||
},
|
},
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
|
@ -25,6 +25,14 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleAlert2Click() {
|
||||||
|
Dialog.alert({
|
||||||
|
message: '无标题alert'
|
||||||
|
}).then((action) => {
|
||||||
|
console.log(action);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
handleConfirmClick() {
|
handleConfirmClick() {
|
||||||
Dialog.confirm({
|
Dialog.confirm({
|
||||||
title: 'confirm标题',
|
title: 'confirm标题',
|
||||||
@ -58,6 +66,7 @@ import { Dialog } from '@youzan/zanui-vue';
|
|||||||
:::demo 消息提示
|
:::demo 消息提示
|
||||||
```html
|
```html
|
||||||
<zan-button @click="handleAlertClick">alert</zan-button>
|
<zan-button @click="handleAlertClick">alert</zan-button>
|
||||||
|
<zan-button @click="handleAlert2Click">无标题alert</zan-button>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
@ -69,6 +78,14 @@ export default {
|
|||||||
}).then((action) => {
|
}).then((action) => {
|
||||||
console.log(action);
|
console.log(action);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
handleAlert2Click() {
|
||||||
|
Dialog.alert({
|
||||||
|
message: '弹窗提示文字,左右始终距离边20PX,上下距离20PX,文字左对齐。弹窗提示文字,左右始终距离边20PX,上下距离20PX,文字左对齐。'
|
||||||
|
}).then((action) => {
|
||||||
|
console.log(action);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -49,20 +49,7 @@ export default {
|
|||||||
|
|
||||||
#### 基础用法
|
#### 基础用法
|
||||||
|
|
||||||
:::demo 基础用法
|
:::demo
|
||||||
```html
|
|
||||||
<div class="uploader-container">
|
|
||||||
<zan-uploader
|
|
||||||
:before-read="logContent"
|
|
||||||
:after-read="logContent">
|
|
||||||
</zan-uploader>
|
|
||||||
</div>
|
|
||||||
```
|
|
||||||
:::
|
|
||||||
|
|
||||||
#### 自定义上传图标
|
|
||||||
|
|
||||||
:::demo 自定义上传图标
|
|
||||||
```html
|
```html
|
||||||
<div class="uploader-container">
|
<div class="uploader-container">
|
||||||
<zan-uploader :after-read="logContent">
|
<zan-uploader :after-read="logContent">
|
||||||
@ -80,7 +67,7 @@ export default {
|
|||||||
| result-type | 读取文件的方式,以base64的方式读取;以文本的方式读取 | `string` | `dataUrl` | `dataUrl`, `text` |
|
| result-type | 读取文件的方式,以base64的方式读取;以文本的方式读取 | `string` | `dataUrl` | `dataUrl`, `text` |
|
||||||
| disable | 是否禁用上传,在图片上传期间设置为true,禁止用户点击此组件上传图片 | `boolean` | `false` | |
|
| disable | 是否禁用上传,在图片上传期间设置为true,禁止用户点击此组件上传图片 | `boolean` | `false` | |
|
||||||
| before-read | 读文件之前的钩子,参数为选择的文件,若返回 false 则停止读取文件。 | `Function` | | |
|
| before-read | 读文件之前的钩子,参数为选择的文件,若返回 false 则停止读取文件。 | `Function` | | |
|
||||||
| after-read | 文件读完之后回调此函数,参数为{name:'文件名',type:'文件类型',size:'文件大小',content:'读的内容'} | `Function` | | |
|
| after-read | 文件读完之后回调此函数,参数为{file:'选择的文件',content:'读的内容'} | `Function` | | |
|
||||||
|
|
||||||
### Slot
|
### Slot
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@youzan/zanui-vue",
|
"name": "@youzan/zanui-vue",
|
||||||
"version": "0.1.1",
|
"version": "0.1.2",
|
||||||
"description": "有赞vue wap组件库",
|
"description": "有赞vue wap组件库",
|
||||||
"main": "lib/zanui.js",
|
"main": "lib/zanui.js",
|
||||||
"style": "lib/zanui-css/index.css",
|
"style": "lib/zanui-css/index.css",
|
||||||
|
@ -76,6 +76,8 @@ var DialogBox = options => {
|
|||||||
DialogBox.alert = function(options) {
|
DialogBox.alert = function(options) {
|
||||||
return DialogBox(merge({
|
return DialogBox(merge({
|
||||||
type: 'alert',
|
type: 'alert',
|
||||||
|
title: '',
|
||||||
|
message: '',
|
||||||
closeOnClickOverlay: false,
|
closeOnClickOverlay: false,
|
||||||
showCancelButton: false
|
showCancelButton: false
|
||||||
}, options));
|
}, options));
|
||||||
@ -84,6 +86,8 @@ DialogBox.alert = function(options) {
|
|||||||
DialogBox.confirm = function(options) {
|
DialogBox.confirm = function(options) {
|
||||||
return DialogBox(merge({
|
return DialogBox(merge({
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
|
title: '',
|
||||||
|
message: '',
|
||||||
closeOnClickOverlay: true,
|
closeOnClickOverlay: true,
|
||||||
showCancelButton: true
|
showCancelButton: true
|
||||||
}, options));
|
}, options));
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<div class="zan-dialog__title" v-text="title"></div>
|
<div class="zan-dialog__title" v-text="title"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="zan-dialog__content" v-if="message">
|
<div class="zan-dialog__content" v-if="message">
|
||||||
<div class="zan-dialog__message" v-html="message"></div>
|
<div class="zan-dialog__message" :class="{ 'zan-dialog__message--notitle': !title }" v-html="message"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="zan-dialog__footer" :class="{ 'is-twobtn': showCancelButton && showConfirmButton }">
|
<div class="zan-dialog__footer" :class="{ 'is-twobtn': showCancelButton && showConfirmButton }">
|
||||||
<button class="zan-dialog__btn zan-dialog__cancel" v-show="showCancelButton" @click="handleAction('cancel')">{{ cancelButtonText }}</button>
|
<button class="zan-dialog__btn zan-dialog__cancel" v-show="showCancelButton" @click="handleAction('cancel')">{{ cancelButtonText }}</button>
|
||||||
|
@ -56,12 +56,7 @@ export default {
|
|||||||
},
|
},
|
||||||
message: {
|
message: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: ''
|
||||||
validator(value) {
|
|
||||||
if (this.type === 'success' || this.type === 'fail') {
|
|
||||||
return value.length <= 16;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
forbidClick: {
|
forbidClick: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="zan-uploader">
|
<div class="zan-uploader">
|
||||||
<slot>
|
<slot>
|
||||||
<div>
|
|
||||||
<zan-button block>上传文件</zan-button>
|
|
||||||
</div>
|
|
||||||
</slot>
|
</slot>
|
||||||
<input type="file" @change="onValueChange" class="zan-uploader__input" ref="input" />
|
<template v-if="disabled">
|
||||||
|
<input type="file" @change="onValueChange" disabled="disabled" class="zan-uploader__input" />
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<input type="file" @change="onValueChange" class="zan-uploader__input" ref="input" />
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -40,12 +43,10 @@
|
|||||||
reader.onload = (e) => {
|
reader.onload = (e) => {
|
||||||
this.afterRead && this.afterRead(
|
this.afterRead && this.afterRead(
|
||||||
{
|
{
|
||||||
name: file.name,
|
file: file,
|
||||||
type: file.type,
|
|
||||||
size: file.size,
|
|
||||||
content: e.target.result
|
content: e.target.result
|
||||||
});
|
});
|
||||||
this.$refs.input.value = '';
|
this.$refs.input && (this.$refs.input.value = '');
|
||||||
};
|
};
|
||||||
if (this.resultType === 'dataUrl') {
|
if (this.resultType === 'dataUrl') {
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@youzan/zanui-css",
|
"name": "@youzan/zanui-css",
|
||||||
"version": "0.1.1",
|
"version": "0.1.2",
|
||||||
"description": "zanui css.",
|
"description": "zanui css.",
|
||||||
"main": "lib/index.css",
|
"main": "lib/index.css",
|
||||||
"style": "lib/index.css",
|
"style": "lib/index.css",
|
||||||
|
@ -46,6 +46,11 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
|
|
||||||
|
@m notitle {
|
||||||
|
color: #333;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@e footer {
|
@e footer {
|
||||||
|
@ -80,7 +80,7 @@ if (typeof window !== 'undefined' && window.Vue) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
install,
|
install,
|
||||||
version: '0.1.1',
|
version: '0.1.2',
|
||||||
Button,
|
Button,
|
||||||
Switch,
|
Switch,
|
||||||
Field,
|
Field,
|
||||||
|
117
test/unit/specs/uploader.spec.js
Normal file
117
test/unit/specs/uploader.spec.js
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
import Uploader from 'packages/uploader';
|
||||||
|
import { mount } from 'avoriaz';
|
||||||
|
|
||||||
|
describe('Uploader', () => {
|
||||||
|
let wrapper;
|
||||||
|
afterEach(() => {
|
||||||
|
wrapper && wrapper.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('enabled', () => {
|
||||||
|
wrapper = mount(Uploader, {
|
||||||
|
propsData: {
|
||||||
|
disabled: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.contains('input')).to.equal(true);
|
||||||
|
expect(wrapper.methods().onValueChange.call(wrapper.vm, { target: { files: [] }})).to.equal(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('Uploader', () => {
|
||||||
|
let wrapper;
|
||||||
|
afterEach(() => {
|
||||||
|
wrapper && wrapper.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('disabled', () => {
|
||||||
|
wrapper = mount(Uploader, {
|
||||||
|
propsData: {
|
||||||
|
disabled: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.contains('input')).to.equal(true);
|
||||||
|
expect(wrapper.methods().onValueChange.call(wrapper.vm, { target: { files: [] }})).to.equal(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('Uploader', () => {
|
||||||
|
let wrapper;
|
||||||
|
afterEach(() => {
|
||||||
|
wrapper && wrapper.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('before read', () => {
|
||||||
|
wrapper = mount(Uploader, {
|
||||||
|
propsData: {
|
||||||
|
disabled: false,
|
||||||
|
beforeRead: () => {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.contains('input')).to.equal(true);
|
||||||
|
expect(wrapper.methods().onValueChange.call(wrapper.vm, { target: { files: [new File([], '')] }})).to.equal(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('Uploader', () => {
|
||||||
|
let wrapper;
|
||||||
|
afterEach(() => {
|
||||||
|
wrapper && wrapper.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('read text', () => {
|
||||||
|
wrapper = mount(Uploader, {
|
||||||
|
propsData: {
|
||||||
|
disabled: false,
|
||||||
|
resultType: 'text',
|
||||||
|
afterRead: (file) => {
|
||||||
|
console.log(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.contains('input')).to.equal(true);
|
||||||
|
expect(wrapper.methods().onValueChange.call(wrapper.vm, { target: { files: [new File([], '/Users')] }})).to.equal(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('Uploader', () => {
|
||||||
|
let wrapper;
|
||||||
|
afterEach(() => {
|
||||||
|
wrapper && wrapper.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('read text no after hook', () => {
|
||||||
|
wrapper = mount(Uploader, {
|
||||||
|
propsData: {
|
||||||
|
disabled: false,
|
||||||
|
resultType: 'text'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.contains('input')).to.equal(true);
|
||||||
|
expect(wrapper.methods().onValueChange.call(wrapper.vm, { target: { files: [new File([], '/Users')] }})).to.equal(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('Uploader', () => {
|
||||||
|
let wrapper;
|
||||||
|
afterEach(() => {
|
||||||
|
wrapper && wrapper.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('read dataUrl', () => {
|
||||||
|
wrapper = mount(Uploader, {
|
||||||
|
propsData: {
|
||||||
|
disabled: false,
|
||||||
|
resultType: 'dataUrl',
|
||||||
|
afterRead: (file) => {
|
||||||
|
console.log(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.contains('input')).to.equal(true);
|
||||||
|
expect(wrapper.methods().onValueChange.call(wrapper.vm, { target: { files: [new File([], '/Users')] }})).to.equal(undefined);
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user