Skip to content

Commit

Permalink
feat: (button) 支持 open-type 等开放能力属性
Browse files Browse the repository at this point in the history
  • Loading branch information
yang1206 committed Sep 18, 2023
1 parent 88d2c1c commit eb72466
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 119 deletions.
25 changes: 24 additions & 1 deletion docs/components/basic/button.md
Expand Up @@ -139,6 +139,8 @@

### Props

> `nut-button`继承了 uni-app button的绝大部分属性,部分小程序特殊属性请查看[button](https://uniapp.dcloud.net.cn/component/button.html)
| 参数 | 说明 | 类型 | 默认值 |
| --------- | ---------------------------------------------------------------------- | ------- | --------- |
| type | 类型,可选值为 `primary` `info` `warning` `danger` `success` `default` | string | `default` |
Expand All @@ -150,6 +152,13 @@
| disabled | 是否禁用按钮 | boolean | `false` |
| block | 是否为块级元素 | boolean | `false` |
| loading | 按钮 `loading` 状态 | boolean | `false` |
| open-type `v1.1.5` | 小程序开放能力 | string [查看 uniapp 文档](https://uniapp.dcloud.net.cn/component/button.html#open-type-%E6%9C%89%E6%95%88%E5%80%BC) | -|
| lang `v1.1.5` | 指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文。 | string | `en` |
| session-from `v1.1.5` | 会话来源,open-type="contact"时有效 | string | - |
| send-message-title `v1.1.5` | 会话内消息卡片标题,open-type="contact"时有效 | string | - |
| send-message-path `v1.1.5` | 会话内消息卡片点击跳转小程序路径,open-type="contact"时有效 | string | - |
| send-message-img `v1.1.5` | 会话内消息卡片图片,open-type="contact"时有效 | string | - |
| show-message-card `v1.1.5` | 是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话会在右下角显示"可能要发送的小程序"提示,用户点击后可以快速发送小程序消息,open-type="contact"时有效 | string | - |

### Slots

Expand All @@ -159,11 +168,25 @@
| icon | 按钮图标 |

### Events
> `nut-button`继承了 uni-app button的open-type回调事件,请查看[button](https://uniapp.dcloud.net.cn/component/button.html)
| 事件名 | 说明 | 回调参数 |
| ------ | -------------- | ------------------- |
| click | 点击按钮时触发 | `event: MouseEvent` |

| getphonenumber `v1.1.5` | 查看[button](https://uniapp.dcloud.net.cn/component/button.html) | |
| getuserinfo `v1.1.5` | 查看[button](https://uniapp.dcloud.net.cn/component/button.html) | |
| error `v1.1.5` | 查看[button](https://uniapp.dcloud.net.cn/component/button.html) | |
| opensetting `v1.1.5` | 查看[button](https://uniapp.dcloud.net.cn/component/button.html) | |
| launchapp `v1.1.5` | 查看[button](https://uniapp.dcloud.net.cn/component/button.html) | |
| contact `v1.1.5` | 查看[button](https://uniapp.dcloud.net.cn/component/button.html) | |
| chooseavatar `v1.1.5` | 查看[button](https://uniapp.dcloud.net.cn/component/button.html) | |
| agreeprivacyauthorization `v1.1.5` | 查看[button](https://uniapp.dcloud.net.cn/component/button.html) | |
| addgroupapp `v1.1.5` | 查看[button](https://uniapp.dcloud.net.cn/component/button.html) | |
| chooseaddress `v1.1.5` | 查看[button](https://uniapp.dcloud.net.cn/component/button.html) |
| chooseinvoicetitle `v1.1.5` | 查看[button](https://uniapp.dcloud.net.cn/component/button.html) |
| subscribe `v1.1.5` | 查看[button](https://uniapp.dcloud.net.cn/component/button.html) |
| login `v1.1.5` | 查看[button](https://uniapp.dcloud.net.cn/component/button.html) |
| im `v1.1.5` | 查看[button](https://uniapp.dcloud.net.cn/component/button.html) |
## 主题定制

### 样式变量
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Expand Up @@ -66,7 +66,7 @@
"@dcloudio/uni-stacktracey": "3.0.0-alpha-3081220230802001",
"@dcloudio/vite-plugin-uni": "3.0.0-alpha-3081220230802001",
"@iconify-json/tabler": "^1.1.79",
"@uni-helper/uni-app-types": "^0.5.8",
"@uni-helper/uni-app-types": "^0.5.10",
"@uni-helper/vite-plugin-uni-components": "^0.0.6",
"@uni-helper/vite-plugin-uni-layouts": "^0.1.1",
"@uni-helper/vite-plugin-uni-manifest": "^0.1.3",
Expand Down
3 changes: 1 addition & 2 deletions example/tsconfig.json
Expand Up @@ -13,13 +13,12 @@
"dom"
],
"types": [
"nutui-uniapp/global.d.ts",
"@dcloudio/types",
"@uni-helper/uni-app-types"
]
},
"include": [
// "node_modules/nutui-uniapp/global.d.ts",
"node_modules/nutui-uniapp/global.d.ts",
"src/**/*.vue",
"src/**/*.ts",
"src/**/*.js",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -47,7 +47,7 @@
"@nutui/touch-emulator": "^1.0.0",
"@types/fs-extra": "^11.0.1",
"@types/node": "^18.15.0",
"@uni-helper/uni-app-types": "^0.5.8",
"@uni-helper/uni-app-types": "^0.5.10",
"@vue/tsconfig": "^0.4.0",
"bumpp": "^9.1.1",
"consola": "^3.2.3",
Expand Down
77 changes: 77 additions & 0 deletions packages/nutui/components/button/button.ts
@@ -1,4 +1,5 @@
import type { ExtractPropTypes, PropType } from 'vue'
import type { ButtonLang, ButtonOnAddgroupappEvent, ButtonOnAgreeprivacyauthorizationEvent, ButtonOnChooseaddressEvent, ButtonOnChooseavatarEvent, ButtonOnChooseinvoicetitleEvent, ButtonOnErrorEvent, ButtonOnGetphonenumberEvent, ButtonOnLaunchappEvent, ButtonOnLoginEvent, ButtonOnOpensettingEvent, ButtonOnSubscribeEvent, ButtonOpenType } from '@uni-helper/uni-app-types'
import { commonProps } from '../_utils'
import type { ButtonFormType, ButtonShape, ButtonSize, ButtonType } from './type'

Expand Down Expand Up @@ -37,10 +38,86 @@ export const buttonProps = {
type: Boolean,
default: false,
},
openType: {
type: String as PropType<ButtonOpenType>,
default: '',
},
lang: {
type: String as PropType<ButtonLang>,
default: 'en',
},
sessionFrom: {
type: String,
default: '',
},
sendMessageTitle: {
type: String,
default: '',
},
sendMessagePath: {
type: String,
default: '',
},
sendMessageImg: {
type: String,
default: '',
},
showMessageCard: {
type: Boolean,
default: false,
},
groupId: {
type: String,
default: '',
},
guildId: {
type: String,
default: '',
},
publicId: {
type: String,
default: '',
},
dataImId: {
type: String,
default: '',
},
dataImType: {
type: String,
default: '',
},
dataGoodsId: {
type: String,
default: '',
},
dataOrderId: {
type: String,
default: '',
},
dataBizLine: {
type: String,
default: '',
},

}

export const buttonEmits = {
click: (evt: MouseEvent) => evt,
getphonenumber: (evt: ButtonOnGetphonenumberEvent) => evt,
getuserinfo: (evt: any) => evt,
error: (evt: ButtonOnErrorEvent) => evt,
opensetting: (evt: ButtonOnOpensettingEvent) => evt,
launchapp: (evt: ButtonOnLaunchappEvent) => evt,
contact: (evt: any) => evt,
chooseavatar: (evt: ButtonOnChooseavatarEvent) => evt,
agreeprivacyauthorization: (evt: ButtonOnAgreeprivacyauthorizationEvent) => evt,
addgroupapp: (evt: ButtonOnAddgroupappEvent) => evt,
chooseaddress: (evt: ButtonOnChooseaddressEvent) => evt,
chooseinvoicetitle: (evt: ButtonOnChooseinvoicetitleEvent) => evt,
subscribe: (evt: ButtonOnSubscribeEvent) => evt,
login: (evt: ButtonOnLoginEvent) => evt,
im: (evt: any) => evt,

}

export type ButtonEmits = typeof buttonEmits
Expand Down
37 changes: 34 additions & 3 deletions packages/nutui/components/button/button.vue
Expand Up @@ -64,11 +64,42 @@ export default defineComponent({
</script>

<template>
<view
<button
:class="[classes, customClass]"
:style="[getStyle, customStyle]"
:form-type="formType === 'button' ? undefined : formType"
:form-type="props.formType === 'button' ? undefined : props.formType"
:open-type="props.openType"
:hover-start-time="10000000"
hover-stop-propagation
:lang="props.lang"
:session-from="props.sessionFrom"
:send-message-title="props.sendMessageTitle"
:send-message-path="props.sendMessagePath"
:send-message-img="props.sendMessageImg"
:show-message-card="props.showMessageCard"
:group-id="props.groupId"
:guild-id="props.guildId"
:public-id="props.publicId"
:data-im-id="props.dataImId"
:data-im-type="props.dataImType"
:data-goods-id="props.dataGoodsId"
:data-order-id="props.dataOrderId"
:data-biz-line="props.dataBizLine"
@click="handleClick"
@getphonenumber="emits('getphonenumber', $event)"
@getuserinfo="emits('getuserinfo', $event)"
@error="emits('error', $event)"
@opensetting="emits('opensetting', $event)"
@addgroupapp="emits('addgroupapp', $event)"
@chooseaddress="emits('chooseaddress', $event)"
@chooseavatar="emits('chooseavatar', $event)"
@chooseinvoicetitle="emits('chooseinvoicetitle', $event)"
@launchapp="emits('launchapp', $event)"
@login="emits('login', $event)"
@subscribe="emits('subscribe', $event)"
@contact="emits('contact', $event)"
@agreeprivacyauthorization="emits('agreeprivacyauthorization', $event)"
@im="emits('im', $event)"
>
<view class="nut-button__wrap">
<Icon v-if="loading" name="loading" class="nut-icon-loading" />
Expand All @@ -77,7 +108,7 @@ export default defineComponent({
<slot />
</view>
</view>
</view>
</button>
</template>

<style lang="scss">
Expand Down
1 change: 0 additions & 1 deletion packages/nutui/components/button/index.scss
Expand Up @@ -283,4 +283,3 @@
background: $button-plain-background-color;
background-origin: border-box;
}

87 changes: 80 additions & 7 deletions packages/nutui/package.json
@@ -1,6 +1,7 @@
{
"id": "nutui-uni",
"name": "nutui-uniapp",
"type": "module",
"displayName": "nutui-uniapp",
"version": "1.1.4",
"description": "京东风格的轻量级移动端 Uniapp、Vue3 组件库(支持小程序开发)",
"author": "yang1206 <y1149221897@outlook.com>",
Expand All @@ -17,7 +18,7 @@
"nutui4",
"vue",
"vue3",
"vue component",
"小程序",
"vue3 component",
"vite"
],
Expand All @@ -41,11 +42,6 @@
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"publishConfig": {
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"files": [
"dist",
"styles",
Expand All @@ -54,11 +50,88 @@
"locale/**",
"global.d.ts"
],
"engines": {
"HBuilderX": "^3.6.17"
},
"publishConfig": {
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"scripts": {
"build": "unbuild",
"stub": "unbuild --stub"
},
"peerDependencies": {
"@uni-helper/uni-app-types": "^0.5.10",
"vue": "^3.2.0"
},
"dcloudext": {
"type": "component-vue",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": "https://www.npmjs.com/package/uniapp-nutui"
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"Vue": {
"vue2": "n",
"vue3": "y"
},
"App": {
"app-vue": "u",
"app-nvue": "u"
},
"H5-mobile": {
"Safari": "y",
"Android Browser": "y",
"微信浏览器(Android)": "y",
"QQ浏览器(Android)": "y"
},
"H5-pc": {
"Chrome": "y",
"IE": "n",
"Edge": "y",
"Firefox": "y",
"Safari": "y"
},
"小程序": {
"微信": "y",
"阿里": "y",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}

0 comments on commit eb72466

Please sign in to comment.