From eec0e5575f3504eb5a21eb877ff1b0363a92819a Mon Sep 17 00:00:00 2001 From: limqhz Date: Thu, 17 Nov 2022 17:05:46 +0800 Subject: [PATCH] project init --- app.json | 3 +- components/action-sheet/README.md | 92 ++++++ components/action-sheet/action-sheet.d.ts | 58 ++++ components/action-sheet/action-sheet.js | 91 ++++++ components/action-sheet/action-sheet.json | 12 + components/action-sheet/action-sheet.wxml | 32 ++ components/action-sheet/action-sheet.wxs | 19 ++ components/action-sheet/action-sheet.wxss | 134 +++++++++ components/action-sheet/index.d.ts | 3 + components/action-sheet/index.js | 3 + components/action-sheet/props.d.ts | 3 + components/action-sheet/props.js | 30 ++ components/action-sheet/show.d.ts | 29 ++ components/action-sheet/show.js | 33 +++ .../template/action-sheet-grid.wxml | 46 +++ .../template/action-sheet-item.wxml | 17 ++ .../template/action-sheet-list.wxml | 11 + components/action-sheet/type.d.ts | 35 +++ components/action-sheet/type.js | 1 + components/checkbox/README.md | 96 ++++++ components/checkbox/checkbox-group-props.d.ts | 3 + components/checkbox/checkbox-group-props.js | 27 ++ components/checkbox/checkbox.d.ts | 98 ++++++ components/checkbox/checkbox.js | 85 ++++++ components/checkbox/checkbox.json | 6 + components/checkbox/checkbox.wxml | 47 +++ components/checkbox/checkbox.wxss | 131 ++++++++ components/checkbox/props.d.ts | 3 + components/checkbox/props.js | 66 +++++ components/checkbox/type.d.ts | 105 +++++++ components/checkbox/type.js | 1 + components/grid/README.md | 82 +++++ components/grid/grid-item-props.d.ts | 3 + components/grid/grid-item-props.js | 27 ++ components/grid/grid-item.d.ts | 24 ++ components/grid/grid-item.js | 111 +++++++ components/grid/grid-item.json | 6 + components/grid/grid-item.wxml | 34 +++ components/grid/grid-item.wxss | 99 +++++++ components/grid/grid.d.ts | 23 ++ components/grid/grid.js | 73 +++++ components/grid/grid.json | 4 + components/grid/grid.wxml | 5 + components/grid/grid.wxss | 38 +++ components/grid/props.d.ts | 3 + components/grid/props.js | 25 ++ components/grid/type.d.ts | 73 +++++ components/grid/type.js | 1 + components/image/README.md | 73 +++++ components/image/image-info.json | 75 +++++ components/image/image.d.ts | 27 ++ components/image/image.js | 92 ++++++ components/image/image.json | 6 + components/image/image.wxml | 45 +++ components/image/image.wxss | 54 ++++ components/image/index.d.ts | 4 + components/image/index.js | 2 + components/image/props.d.ts | 3 + components/image/props.js | 38 +++ components/image/type.d.ts | 38 +++ components/image/type.js | 1 + components/mixins/page-scroll.d.ts | 7 + components/mixins/page-scroll.js | 50 ++++ components/mixins/transition.d.ts | 1 + components/mixins/transition.js | 123 ++++++++ components/overlay/README.md | 42 +++ components/overlay/overlay.d.ts | 40 +++ components/overlay/overlay.js | 69 +++++ components/overlay/overlay.json | 3 + components/overlay/overlay.wxml | 19 ++ components/overlay/overlay.wxss | 42 +++ components/popup/README.md | 47 +++ components/popup/popup.d.ts | 24 ++ components/popup/popup.js | 59 ++++ components/popup/popup.json | 7 + components/popup/popup.wxml | 25 ++ components/popup/popup.wxss | 99 +++++++ components/popup/props.d.ts | 3 + components/popup/props.js | 47 +++ components/popup/type.d.ts | 54 ++++ components/popup/type.js | 1 + components/swiper/README.md | 92 ++++++ components/swiper/common/constants.d.ts | 11 + components/swiper/common/constants.js | 5 + components/swiper/props.d.ts | 3 + components/swiper/props.js | 45 +++ components/swiper/swiper-item.d.ts | 10 + components/swiper/swiper-item.js | 37 +++ components/swiper/swiper-item.json | 3 + components/swiper/swiper-item.wxml | 3 + components/swiper/swiper-item.wxss | 33 +++ components/swiper/swiper-nav.d.ts | 37 +++ components/swiper/swiper-nav.js | 63 ++++ components/swiper/swiper-nav.json | 3 + components/swiper/swiper-nav.wxml | 18 ++ components/swiper/swiper-nav.wxss | 178 +++++++++++ components/swiper/swiper.d.ts | 71 +++++ components/swiper/swiper.js | 280 ++++++++++++++++++ components/swiper/swiper.json | 7 + components/swiper/swiper.wxml | 43 +++ components/swiper/swiper.wxs | 184 ++++++++++++ components/swiper/swiper.wxss | 44 +++ components/swiper/type.d.ts | 52 ++++ components/swiper/type.js | 1 + pages/today/index.js | 83 ++++-- pages/today/index.json | 3 +- pages/today/index.wxml | 15 +- pages/today/index.wxss | 24 +- 108 files changed, 4483 insertions(+), 36 deletions(-) create mode 100644 components/action-sheet/README.md create mode 100644 components/action-sheet/action-sheet.d.ts create mode 100644 components/action-sheet/action-sheet.js create mode 100644 components/action-sheet/action-sheet.json create mode 100644 components/action-sheet/action-sheet.wxml create mode 100644 components/action-sheet/action-sheet.wxs create mode 100644 components/action-sheet/action-sheet.wxss create mode 100644 components/action-sheet/index.d.ts create mode 100644 components/action-sheet/index.js create mode 100644 components/action-sheet/props.d.ts create mode 100644 components/action-sheet/props.js create mode 100644 components/action-sheet/show.d.ts create mode 100644 components/action-sheet/show.js create mode 100644 components/action-sheet/template/action-sheet-grid.wxml create mode 100644 components/action-sheet/template/action-sheet-item.wxml create mode 100644 components/action-sheet/template/action-sheet-list.wxml create mode 100644 components/action-sheet/type.d.ts create mode 100644 components/action-sheet/type.js create mode 100644 components/checkbox/README.md create mode 100644 components/checkbox/checkbox-group-props.d.ts create mode 100644 components/checkbox/checkbox-group-props.js create mode 100644 components/checkbox/checkbox.d.ts create mode 100644 components/checkbox/checkbox.js create mode 100644 components/checkbox/checkbox.json create mode 100644 components/checkbox/checkbox.wxml create mode 100644 components/checkbox/checkbox.wxss create mode 100644 components/checkbox/props.d.ts create mode 100644 components/checkbox/props.js create mode 100644 components/checkbox/type.d.ts create mode 100644 components/checkbox/type.js create mode 100644 components/grid/README.md create mode 100644 components/grid/grid-item-props.d.ts create mode 100644 components/grid/grid-item-props.js create mode 100644 components/grid/grid-item.d.ts create mode 100644 components/grid/grid-item.js create mode 100644 components/grid/grid-item.json create mode 100644 components/grid/grid-item.wxml create mode 100644 components/grid/grid-item.wxss create mode 100644 components/grid/grid.d.ts create mode 100644 components/grid/grid.js create mode 100644 components/grid/grid.json create mode 100644 components/grid/grid.wxml create mode 100644 components/grid/grid.wxss create mode 100644 components/grid/props.d.ts create mode 100644 components/grid/props.js create mode 100644 components/grid/type.d.ts create mode 100644 components/grid/type.js create mode 100644 components/image/README.md create mode 100644 components/image/image-info.json create mode 100644 components/image/image.d.ts create mode 100644 components/image/image.js create mode 100644 components/image/image.json create mode 100644 components/image/image.wxml create mode 100644 components/image/image.wxss create mode 100644 components/image/index.d.ts create mode 100644 components/image/index.js create mode 100644 components/image/props.d.ts create mode 100644 components/image/props.js create mode 100644 components/image/type.d.ts create mode 100644 components/image/type.js create mode 100644 components/mixins/page-scroll.d.ts create mode 100644 components/mixins/page-scroll.js create mode 100644 components/mixins/transition.d.ts create mode 100644 components/mixins/transition.js create mode 100644 components/overlay/README.md create mode 100644 components/overlay/overlay.d.ts create mode 100644 components/overlay/overlay.js create mode 100644 components/overlay/overlay.json create mode 100644 components/overlay/overlay.wxml create mode 100644 components/overlay/overlay.wxss create mode 100644 components/popup/README.md create mode 100644 components/popup/popup.d.ts create mode 100644 components/popup/popup.js create mode 100644 components/popup/popup.json create mode 100644 components/popup/popup.wxml create mode 100644 components/popup/popup.wxss create mode 100644 components/popup/props.d.ts create mode 100644 components/popup/props.js create mode 100644 components/popup/type.d.ts create mode 100644 components/popup/type.js create mode 100644 components/swiper/README.md create mode 100644 components/swiper/common/constants.d.ts create mode 100644 components/swiper/common/constants.js create mode 100644 components/swiper/props.d.ts create mode 100644 components/swiper/props.js create mode 100644 components/swiper/swiper-item.d.ts create mode 100644 components/swiper/swiper-item.js create mode 100644 components/swiper/swiper-item.json create mode 100644 components/swiper/swiper-item.wxml create mode 100644 components/swiper/swiper-item.wxss create mode 100644 components/swiper/swiper-nav.d.ts create mode 100644 components/swiper/swiper-nav.js create mode 100644 components/swiper/swiper-nav.json create mode 100644 components/swiper/swiper-nav.wxml create mode 100644 components/swiper/swiper-nav.wxss create mode 100644 components/swiper/swiper.d.ts create mode 100644 components/swiper/swiper.js create mode 100644 components/swiper/swiper.json create mode 100644 components/swiper/swiper.wxml create mode 100644 components/swiper/swiper.wxs create mode 100644 components/swiper/swiper.wxss create mode 100644 components/swiper/type.d.ts create mode 100644 components/swiper/type.js diff --git a/app.json b/app.json index 44e5032..fecc057 100644 --- a/app.json +++ b/app.json @@ -7,7 +7,8 @@ "pages/message/index" ], "usingComponents": { - "t-icon": "/components/icon/icon" + "t-icon": "/components/icon/icon", + "t-checkbox": "/components/checkbox/checkbox" }, "window": { "backgroundTextStyle": "light", diff --git a/components/action-sheet/README.md b/components/action-sheet/README.md new file mode 100644 index 0000000..4483838 --- /dev/null +++ b/components/action-sheet/README.md @@ -0,0 +1,92 @@ +--- +title: ActionSheet 动作面板 +description: 由用户操作后触发的一种特定的模态弹出框 ,呈现一组与当前情境相关的两个或多个选项。 +spline: data +isComponent: true +--- + + +## 引入 + +全局引入,在 miniprogram 根目录下的`app.json`中配置,局部引入,在需要引入的页面或组件的`index.json`中配置。 + +```json +"usingComponents": { + "t-action-sheet": "tdesign-miniprogram/action-sheet/action-sheet", +} +``` + +## 代码演示 + +### 基础用法 + +{{ list }} + +### 图标列表型 + +{{ icon-list }} + +### 宫格型 + +{{ grid }} + +### 宫格型-多页 + +{{ grid-multi }} + +### 支持指令调用 + +```javascript +import ActionSheet, { ActionSheetTheme } from 'tdesign-miniprogram/action-sheet/index'; + +// 指令调用不同于组件引用不需要传入visible +const basicListOption: ActionSheetShowOption = { + theme: ActionSheetTheme.List, + selector: '#t-action-sheet', + items: [ + { + label: '默认选项', + }, + { + label: '失效选项', + disabled: true, + }, + { + label: '警告选项', + color: '#e34d59', + }, + ], +}; + +const handler = ActionSheet.show(basicListOption); +``` + +指令调用的关闭如下 + +```javascript +handler.close(); +``` + + +## API +### ActionSheet Props + +名称 | 类型 | 默认值 | 说明 | 必传 +-- | -- | -- | -- | -- +cancel-text | String | 取消 | 设置取消按钮的文本 | N +count | Number | 8 | 设置每页展示菜单的数量,仅当 type=grid 时有效 | N +items | Array | - | 必需。菜单项。TS 类型:`Array` `interface ActionSheetItem {label: string; color?: string; disabled?: boolean; icon?: string; }`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/action-sheet/type.ts) | Y +show-cancel | Boolean | true | 是否显示取消按钮 | N +theme | String | list | 展示类型,列表和表格形式展示。可选项:list/grid | N +visible | Boolean | null | 必需。显示与隐藏 | Y +default-visible | Boolean | false | 必需。显示与隐藏。非受控属性 | Y +external-classes | Array | - | 组件类名,分别用于设置 组件外层元素、组件内容部分、取消按钮 等元素类名。`['t-class', 't-class-content', 't-class-cancel']` | N + +### ActionSheet Events + +名称 | 参数 | 描述 +-- | -- | -- +visible-change | `(visible: Boolean)` | 当浮层隐藏或显示时触发。 +cancel | - | 点击取消按钮时触发 +selected | `(selected: ActionSheetItem | String, index: Number)` | 选择菜单项时触发 + diff --git a/components/action-sheet/action-sheet.d.ts b/components/action-sheet/action-sheet.d.ts new file mode 100644 index 0000000..6dc9f74 --- /dev/null +++ b/components/action-sheet/action-sheet.d.ts @@ -0,0 +1,58 @@ +import { SuperComponent } from '../common/src/index'; +export default class ActionSheet extends SuperComponent { + static show: (options: import("./show").ActionSheetShowOption) => WechatMiniprogram.Component.TrivialInstance; + externalClasses: string[]; + properties: { + cancelText?: { + type: StringConstructor; + value?: string; + }; + count?: { + type: NumberConstructor; + value?: number; + }; + items: { + type: ArrayConstructor; + value?: (string | import("./type").ActionSheetItem)[]; + }; + showCancel?: { + type: BooleanConstructor; + value?: boolean; + }; + theme?: { + type: StringConstructor; + value?: "list" | "grid"; + }; + visible: { + type: BooleanConstructor; + value?: boolean; + }; + defaultVisible: { + type: BooleanConstructor; + value?: boolean; + }; + }; + data: { + prefix: string; + classPrefix: string; + gridThemeItems: any[]; + currentSwiperIndex: number; + }; + controlledProps: { + key: string; + event: string; + }[]; + ready(): void; + methods: { + onSwiperChange(e: WechatMiniprogram.TouchEvent): void; + splitGridThemeActions(): void; + show(options: any): void; + memoInitialData(): void; + close(): void; + onPopupVisibleChange({ detail }: { + detail: any; + }): void; + onSelect(event: WechatMiniprogram.TouchEvent): void; + onCancel(): void; + }; +} diff --git a/components/action-sheet/action-sheet.js b/components/action-sheet/action-sheet.js new file mode 100644 index 0000000..06880cc --- /dev/null +++ b/components/action-sheet/action-sheet.js @@ -0,0 +1,91 @@ +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +import { chunk } from '../common/utils'; +import { SuperComponent, wxComponent } from '../common/src/index'; +import config from '../common/config'; +import { ActionSheetTheme, show } from './show'; +import props from './props'; +const { prefix } = config; +const name = `${prefix}-action-sheet`; +let ActionSheet = class ActionSheet extends SuperComponent { + constructor() { + super(...arguments); + this.externalClasses = [`${prefix}-class`, `${prefix}-class-content`, `${prefix}-class-cancel`]; + this.properties = Object.assign({}, props); + this.data = { + prefix, + classPrefix: name, + gridThemeItems: [], + currentSwiperIndex: 0, + }; + this.controlledProps = [ + { + key: 'visible', + event: 'visible-change', + }, + ]; + this.methods = { + onSwiperChange(e) { + const { detail: { current }, } = e; + this.setData({ + currentSwiperIndex: current, + }); + }, + splitGridThemeActions() { + if (this.data.theme !== ActionSheetTheme.Grid) + return; + this.setData({ + gridThemeItems: chunk(this.data.items, this.data.count), + }); + }, + show(options) { + this.setData(Object.assign(Object.assign(Object.assign({}, this.initialData), options), { visible: true })); + this.splitGridThemeActions(); + this.autoClose = true; + this._trigger('visible-change', { visible: true }); + }, + memoInitialData() { + this.initialData = Object.assign(Object.assign({}, this.properties), this.data); + }, + close() { + this._trigger('visible-change', { visible: false }); + }, + onPopupVisibleChange({ detail }) { + if (!detail.visible) { + this._trigger('visible-change', { visible: false }); + } + if (this.autoClose) { + this.setData({ visible: false }); + this.autoClose = false; + } + }, + onSelect(event) { + const { currentSwiperIndex, items, gridThemeItems, count, theme } = this.data; + const { index } = event.currentTarget.dataset; + const isSwiperMode = theme === ActionSheetTheme.Grid; + const item = isSwiperMode ? gridThemeItems[currentSwiperIndex][index] : items[index]; + const realIndex = isSwiperMode ? index + currentSwiperIndex * count : index; + if (item) { + this.triggerEvent('selected', { selected: item, index: realIndex }); + this._trigger('visible-change', { visible: false }); + } + }, + onCancel() { + this.triggerEvent('cancel'); + }, + }; + } + ready() { + this.memoInitialData(); + this.splitGridThemeActions(); + } +}; +ActionSheet.show = show; +ActionSheet = __decorate([ + wxComponent() +], ActionSheet); +export default ActionSheet; diff --git a/components/action-sheet/action-sheet.json b/components/action-sheet/action-sheet.json new file mode 100644 index 0000000..a52f661 --- /dev/null +++ b/components/action-sheet/action-sheet.json @@ -0,0 +1,12 @@ +{ + "component": true, + "usingComponents": { + "t-icon": "../icon/icon", + "t-popup": "../popup/popup", + "t-swiper": "../swiper/swiper", + "t-swiper-item": "../swiper/swiper-item", + "t-image": "../image/image", + "t-grid": "../grid/grid", + "t-grid-item": "../grid/grid-item" + } +} diff --git a/components/action-sheet/action-sheet.wxml b/components/action-sheet/action-sheet.wxml new file mode 100644 index 0000000..59e3f7e --- /dev/null +++ b/components/action-sheet/action-sheet.wxml @@ -0,0 +1,32 @@ + + + + + + + +