diff --git a/example/app.json b/example/app.json
index b8d1b391..5855470f 100644
--- a/example/app.json
+++ b/example/app.json
@@ -139,6 +139,7 @@
"van-toast-demo": "./dist/toast/demo/index",
"van-transition": "./dist/transition/index",
"van-tree-select": "./dist/tree-select/index",
+ "van-tree-select-demo": "./dist/tree-select/demo/index",
"van-datetime-picker": "./dist/datetime-picker/index",
"van-rate": "./dist/rate/index",
"van-rate-demo": "./dist/rate/demo/index",
diff --git a/example/pages/tree-select/config.js b/example/pages/tree-select/config.js
deleted file mode 100644
index 2b06954b..00000000
--- a/example/pages/tree-select/config.js
+++ /dev/null
@@ -1,52 +0,0 @@
-export default {
- pro1Name: '浙江',
- pro1: [
- {
- text: '杭州',
- id: 1,
- },
- {
- text: '温州',
- id: 2,
- },
- {
- text: '宁波',
- id: 3,
- disabled: true,
- },
- {
- text: '义乌',
- id: 4,
- },
- ],
- pro2Name: '江苏',
- pro2: [
- {
- text: '南京',
- id: 5,
- },
- {
- text: '无锡',
- id: 6,
- },
- {
- text: '徐州',
- id: 7,
- },
- {
- text: '苏州',
- id: 8,
- },
- ],
- pro3Name: '福建',
- pro3: [
- {
- text: '泉州',
- id: 9,
- },
- {
- text: '厦门',
- id: 10,
- },
- ],
-};
diff --git a/example/pages/tree-select/index.js b/example/pages/tree-select/index.js
index 30622435..cc11dfda 100644
--- a/example/pages/tree-select/index.js
+++ b/example/pages/tree-select/index.js
@@ -1,68 +1,3 @@
import Page from '../../common/page';
-import config from './config';
-const items = [
- {
- text: config.pro1Name,
- children: config.pro1,
- },
- {
- text: config.pro2Name,
- children: config.pro2,
- },
- {
- text: config.pro3Name,
- disabled: true,
- children: config.pro3,
- },
-];
-
-Page({
- data: {
- items,
- badgeItems: items.slice(0, 2).map((item, index) => {
- if (index === 0) {
- return { ...item, dot: true };
- }
- if (index === 1) {
- return { ...item, badge: 5 };
- }
-
- return item;
- }),
- mainActiveIndex: 0,
- activeId: 0,
- mainActiveIndexMulti: 0,
- activeIdMulti: [],
- },
-
- onClickNav({ detail }) {
- this.setData({
- mainActiveIndex: detail.index || 0,
- });
- },
-
- onClickItem({ detail }) {
- const activeId = this.data.activeId === detail.id ? null : detail.id;
-
- this.setData({ activeId });
- },
-
- onClickNavMulti({ detail }) {
- this.setData({
- mainActiveIndexMulti: detail.index || 0,
- });
- },
-
- onClickItemMulti({ detail }) {
- const { activeIdMulti } = this.data;
- const idx = activeIdMulti.indexOf(detail.id);
- if (idx > -1) {
- activeIdMulti.splice(idx, 1);
- } else {
- activeIdMulti.push(detail.id);
- }
-
- this.setData({ activeIdMulti });
- },
-});
+Page();
diff --git a/example/pages/tree-select/index.wxml b/example/pages/tree-select/index.wxml
index 2af553bd..1e3d91d2 100644
--- a/example/pages/tree-select/index.wxml
+++ b/example/pages/tree-select/index.wxml
@@ -1,56 +1 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/example/pages/tree-select/index.wxss b/example/pages/tree-select/index.wxss
deleted file mode 100644
index d57997ae..00000000
--- a/example/pages/tree-select/index.wxss
+++ /dev/null
@@ -1 +0,0 @@
-/* pages/tree-select/index.wxss */
diff --git a/packages/tree-select/demo/index.json b/packages/tree-select/demo/index.json
new file mode 100644
index 00000000..bf48c327
--- /dev/null
+++ b/packages/tree-select/demo/index.json
@@ -0,0 +1,8 @@
+{
+ "component": true,
+ "usingComponents": {
+ "van-image": "../../image/index",
+ "van-tree-select": "../../tree-select/index",
+ "demo-block": "../../../example/components/demo-block/index"
+ }
+}
diff --git a/packages/tree-select/demo/index.ts b/packages/tree-select/demo/index.ts
new file mode 100644
index 00000000..83bca520
--- /dev/null
+++ b/packages/tree-select/demo/index.ts
@@ -0,0 +1,121 @@
+import { VantComponent } from '../../common/component';
+
+const config = {
+ pro1Name: '浙江',
+ pro1: [
+ {
+ text: '杭州',
+ id: 1,
+ },
+ {
+ text: '温州',
+ id: 2,
+ },
+ {
+ text: '宁波',
+ id: 3,
+ disabled: true,
+ },
+ {
+ text: '义乌',
+ id: 4,
+ },
+ ],
+ pro2Name: '江苏',
+ pro2: [
+ {
+ text: '南京',
+ id: 5,
+ },
+ {
+ text: '无锡',
+ id: 6,
+ },
+ {
+ text: '徐州',
+ id: 7,
+ },
+ {
+ text: '苏州',
+ id: 8,
+ },
+ ],
+ pro3Name: '福建',
+ pro3: [
+ {
+ text: '泉州',
+ id: 9,
+ },
+ {
+ text: '厦门',
+ id: 10,
+ },
+ ],
+};
+const items = [
+ {
+ text: config.pro1Name,
+ children: config.pro1,
+ },
+ {
+ text: config.pro2Name,
+ children: config.pro2,
+ },
+ {
+ text: config.pro3Name,
+ disabled: true,
+ children: config.pro3,
+ },
+];
+
+VantComponent({
+ data: {
+ items,
+ badgeItems: items.slice(0, 2).map((item, index) => {
+ if (index === 0) {
+ return { ...item, dot: true };
+ }
+ if (index === 1) {
+ return { ...item, badge: 5 };
+ }
+
+ return item;
+ }),
+ mainActiveIndex: 0,
+ activeId: 0,
+ mainActiveIndexMulti: 0,
+ activeIdMulti: [],
+ },
+
+ methods: {
+ onClickNav({ detail }) {
+ this.setData({
+ mainActiveIndex: detail.index || 0,
+ });
+ },
+
+ onClickItem({ detail }) {
+ const activeId = this.data.activeId === detail.id ? null : detail.id;
+
+ this.setData({ activeId });
+ },
+
+ onClickNavMulti({ detail }) {
+ this.setData({
+ mainActiveIndexMulti: detail.index || 0,
+ });
+ },
+
+ onClickItemMulti({ detail }) {
+ const { activeIdMulti }: { activeIdMulti: any } = this.data;
+ const idx = activeIdMulti.indexOf(detail.id);
+ if (idx > -1) {
+ activeIdMulti.splice(idx, 1);
+ } else {
+ activeIdMulti.push(detail.id);
+ }
+
+ this.setData({ activeIdMulti });
+ },
+ },
+});
diff --git a/packages/tree-select/demo/index.wxml b/packages/tree-select/demo/index.wxml
new file mode 100644
index 00000000..2af553bd
--- /dev/null
+++ b/packages/tree-select/demo/index.wxml
@@ -0,0 +1,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/tree-select/test/__snapshots__/demo.spec.ts.snap b/packages/tree-select/test/__snapshots__/demo.spec.ts.snap
new file mode 100644
index 00000000..e1b46128
--- /dev/null
+++ b/packages/tree-select/test/__snapshots__/demo.spec.ts.snap
@@ -0,0 +1,593 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render demo and match snapshot 1`] = `
+
+
+
+
+ 单选模式
+
+
+
+
+
+
+
+
+
+
+
+ 杭州
+
+
+
+
+ 温州
+
+
+
+
+ 宁波
+
+
+
+
+ 义乌
+
+
+
+
+
+
+
+
+
+
+ 多选模式
+
+
+
+
+
+
+
+
+
+
+
+ 杭州
+
+
+
+
+ 温州
+
+
+
+
+ 宁波
+
+
+
+
+ 义乌
+
+
+
+
+
+
+
+
+
+
+ 自定义内容
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 徽标提示
+
+
+
+
+
+
+
+
+
+
+
+ 杭州
+
+
+
+
+ 温州
+
+
+
+
+ 宁波
+
+
+
+
+ 义乌
+
+
+
+
+
+
+
+
+`;
diff --git a/packages/tree-select/test/demo.spec.ts b/packages/tree-select/test/demo.spec.ts
new file mode 100644
index 00000000..48f5c77b
--- /dev/null
+++ b/packages/tree-select/test/demo.spec.ts
@@ -0,0 +1,15 @@
+import path from 'path';
+import simulate from 'miniprogram-simulate';
+
+test('should render demo and match snapshot', () => {
+ try {
+ const id = simulate.load(path.resolve(__dirname, '../demo/index'), {
+ rootPath: path.resolve(__dirname, '../../'),
+ });
+ const comp = simulate.render(id);
+ comp.attach(document.createElement('parent-wrapper'));
+ expect(comp.toJSON()).toMatchSnapshot();
+ } catch (e) {
+ console.error(e);
+ }
+});