first commit

This commit is contained in:
编码猿
2024-09-27 01:32:49 +08:00
commit 28ebe05a64
7399 changed files with 1174529 additions and 0 deletions

View File

@@ -0,0 +1 @@
9ffe2403-d8d9-48f3-b76b-c0a42716afa6

View File

@@ -0,0 +1,262 @@
import baseComponent from '../helpers/baseComponent'
import classNames from '../helpers/classNames'
const defaults = {
prefixCls: 'wux-dialog',
title: '',
content: '',
buttons: [],
verticalButtons: !1,
resetOnClose: false,
closable: false,
mask: true,
maskClosable: true,
zIndex: 1000,
}
const defaultOptions = {
onCancel() {},
cancelText: '取消',
cancelType: 'default',
onConfirm() {},
confirmText: '确定',
confirmType: 'primary',
}
baseComponent({
useFunc: true,
data: defaults,
computed: {
classes: ['prefixCls, buttons, verticalButtons', function(prefixCls, btns, verticalButtons) {
const prompt = `${prefixCls}__prompt`
const input = `${prefixCls}__input`
const buttons = classNames(`${prefixCls}__buttons`, {
[`${prefixCls}__buttons--${verticalButtons ? 'vertical' : 'horizontal'}`]: true,
})
const button = btns.map((button) => {
const wrap = classNames(`${prefixCls}__button`, {
[`${prefixCls}__button--${button.type || 'default'}`]: button.type || 'default',
[`${prefixCls}__button--bold`]: button.bold,
[`${prefixCls}__button--disabled`]: button.disabled,
[`${button.className}`]: button.className,
})
const hover = button.hoverClass && button.hoverClass !== 'default' ? button.hoverClass : `${prefixCls}__button--hover`
return {
wrap,
hover,
}
})
return {
prompt,
input,
buttons,
button,
}
}],
},
methods: {
/**
* 组件关闭时重置其内部数据
*/
onClosed() {
if (this.data.resetOnClose) {
const params = {
...this.$$mergeOptionsToData(defaults),
prompt: null,
}
this.$$setData(params)
}
},
/**
* 点击 x 或 mask 回调
*/
onClose() {
this.hide()
},
/**
* 隐藏
*/
hide(cb) {
this.$$setData({ in: false })
if (typeof cb === 'function') {
cb.call(this)
}
},
/**
* 显示
*/
show(opts = {}) {
const options = this.$$mergeOptionsAndBindMethods(Object.assign({}, defaults, opts))
this.$$setData({ in: true, ...options })
this.originalButtons = options.buttons
return this.hide.bind(this)
},
/**
* 触发事件
*/
runCallbacks(e, method) {
const { index } = e.currentTarget.dataset
const button = this.originalButtons[index]
if (!button.disabled) {
this.hide(() => typeof button[method] === 'function' && button[method](e))
}
},
/**
* 按钮点击事件
*/
buttonTapped(e) {
this.runCallbacks(e, 'onTap')
},
/**
* 用户点击该按钮时,会返回获取到的用户信息,回调的detail数据与wx.getUserInfo返回的一致,open-type="getUserInfo"时有效
*/
bindgetuserinfo(e) {
this.runCallbacks(e, 'onGetUserInfo')
},
/**
* 客服消息回调,open-type="contact"时有效
*/
bindcontact(e) {
this.runCallbacks(e, 'onContact')
},
/**
* 获取用户手机号回调,open-type=getPhoneNumber时有效
*/
bindgetphonenumber(e) {
this.runCallbacks(e, 'onGotPhoneNumber')
},
/**
* 在打开授权设置页后回调,open-type=openSetting时有效
*/
bindopensetting(e) {
this.runCallbacks(e, 'onOpenSetting')
},
/**
* 当使用开放能力时,发生错误的回调,open-type=launchApp时有效
*/
onError(e) {
this.runCallbacks(e, 'onError')
},
/**
* 当键盘输入时,触发 input 事件
*/
bindinput(e) {
this.$$setData({
'prompt.response': e.detail.value,
})
},
/**
* 显示dialog组件
* @param {Object} opts 配置项
* @param {String} opts.title 提示标题
* @param {String} opts.content 提示文本
* @param {Boolean} opts.verticalButtons 是否显示垂直按钮布局
* @param {Array} opts.buttons 按钮
* @param {String} opts.buttons.text 按钮的文字
* @param {String} opts.buttons.type 按钮的类型
* @param {Boolean} opts.buttons.bold 是否加粗按钮的文字
* @param {Function} opts.buttons.onTap 按钮的点击事件
*/
open(opts = {}) {
return this.show(opts)
},
/**
* 显示dialog组件
* @param {Object} opts 配置项
* @param {String} opts.title 提示标题
* @param {String} opts.content 提示文本
* @param {String} opts.confirmText 确定按钮的文字,默认为"确定"
* @param {String} opts.confirmType 确定按钮的类型
* @param {Function} opts.onConfirm 确定按钮的点击事件
*/
alert(opts = {}) {
return this.open(Object.assign({
buttons: [{
text: opts.confirmText || defaultOptions.confirmText,
type: opts.confirmType || defaultOptions.confirmType,
onTap: (e) => {
typeof opts.onConfirm === 'function' && opts.onConfirm(e)
},
} ],
}, opts))
},
/**
* 显示dialog组件
* @param {Object} opts 配置项
* @param {String} opts.title 提示标题
* @param {String} opts.content 提示文本
* @param {String} opts.confirmText 确定按钮的文字,默认为"确定"
* @param {String} opts.confirmType 确定按钮的类型
* @param {Function} opts.onConfirm 确定按钮的点击事件
* @param {String} opts.cancelText 取消按钮的文字,默认为"取消"
* @param {String} opts.cancelType 取消按钮的类型
* @param {Function} opts.onCancel 取消按钮的点击事件
*/
confirm(opts = {}) {
return this.open(Object.assign({
buttons: [{
text: opts.cancelText || defaultOptions.cancelText,
type: opts.cancelType || defaultOptions.cancelType,
onTap: (e) => {
typeof opts.onCancel === 'function' && opts.onCancel(e)
},
},
{
text: opts.confirmText || defaultOptions.confirmText,
type: opts.confirmType || defaultOptions.confirmType,
onTap: (e) => {
typeof opts.onConfirm === 'function' && opts.onConfirm(e)
},
}],
}, opts))
},
/**
* 显示dialog组件
* @param {Object} opts 配置项
* @param {String} opts.title 提示标题
* @param {String} opts.content 提示文本
* @param {String} opts.fieldtype input 的类型,有效值:text, number, idcard, digit
* @param {Boolean} opts.password 是否是密码类型
* @param {String} opts.defaultText 默认值
* @param {String} opts.placeholder 输入框为空时占位符
* @param {Number} opts.maxlength 最大输入长度,设置为 -1 的时候不限制最大长度
* @param {String} opts.confirmText 确定按钮的文字,默认为"确定"
* @param {String} opts.confirmType 确定按钮的类型
* @param {Function} opts.onConfirm 确定按钮的点击事件
* @param {String} opts.cancelText 取消按钮的文字,默认为"取消"
* @param {String} opts.cancelType 取消按钮的类型
* @param {Function} opts.onCancel 取消按钮的点击事件
*/
prompt(opts = {}) {
const prompt = {
fieldtype: opts.fieldtype ? opts.fieldtype : 'text',
password: !!opts.password,
response: opts.defaultText ? opts.defaultText : '',
placeholder: opts.placeholder ? opts.placeholder : '',
maxlength: opts.maxlength ? parseInt(opts.maxlength) : '',
}
return this.open(Object.assign({
prompt: prompt,
buttons: [{
text: opts.cancelText || defaultOptions.cancelText,
type: opts.cancelType || defaultOptions.cancelType,
onTap: (e) => {
typeof opts.onCancel === 'function' && opts.onCancel(e)
},
},
{
text: opts.confirmText || defaultOptions.confirmText,
type: opts.confirmType || defaultOptions.confirmType,
onTap: (e) => {
typeof opts.onConfirm === 'function' && opts.onConfirm(e, this.data.prompt.response)
},
}],
}, opts))
},
},
})

View File

@@ -0,0 +1,6 @@
{
"component": true,
"usingComponents": {
"wux-popup": "../popup/index"
}
}

View File

@@ -0,0 +1,56 @@
<wux-popup
visible="{{ in }}"
z-index="{{ zIndex }}"
closable="{{ closable }}"
mask="{{ mask }}"
mask-closable="{{ maskClosable }}"
bind:close="onClose"
bind:closed="onClosed"
>
<view slot="header">{{ title }}</view>
<view wx:if="{{ content || prompt }}">
<text>{{ content }}</text>
<view class="{{ classes.prompt }}" wx:if="{{ prompt }}">
<label>
<input
type="{{ prompt.fieldtype }}"
class="{{ classes.input }}"
value="{{ prompt.response }}"
password="{{ prompt.password }}"
placeholder="{{ prompt.placeholder }}"
maxlength="{{ maxlength }}"
bindinput="bindinput"
/>
</label>
</view>
</view>
<view slot="footer" class="{{ classes.buttons }}">
<block wx:for="{{ buttons }}" wx:for-item="button" wx:key="">
<button
class="{{ classes.button[index].wrap }}"
disabled="{{ button.disabled }}"
open-type="{{ button.openType }}"
hover-class="{{ !button.disabled ? classes.button[index].hover : 'none' }}"
hover-stop-propagation="{{ button.hoverStopPropagation }}"
hover-start-time="{{ button.hoverStartTime || 20 }}"
hover-stay-time="{{ button.hoverStayTime || 70 }}"
lang="{{ button.lang || 'en' }}"
bindgetuserinfo="bindgetuserinfo"
session-from="{{ button.sessionFrom }}"
send-message-title="{{ button.sendMessageTitle }}"
send-message-path="{{ button.sendMessagePath }}"
send-message-img="{{ button.sendMessageImg }}"
show-message-card="{{ button.showMessageCard }}"
bindcontact="bindcontact"
bindgetphonenumber="bindgetphonenumber"
app-parameter="{{ button.appParameter }}"
binderror="onError"
bindopensetting="bindopensetting"
data-index="{{ index }}"
bindtap="buttonTapped"
>
{{ button.text }}
</button>
</block>
</view>
</wux-popup>

View File

@@ -0,0 +1,116 @@
.wux-dialog__button {
padding: 0;
margin: 0;
border-radius: 0;
color: inherit!important;
background: 0 0!important;
font-size: inherit;
font-weight: 400;
line-height: inherit;
text-align: inherit;
text-decoration: none;
overflow: visible;
min-height: 0!important;
width: auto!important;
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
display: block;
-ms-flex: 1;
flex: 1;
color: #33cd5f!important;
position: relative
}
.wux-dialog__button::after {
display: block;
position: static;
top: auto;
left: auto;
width: auto;
height: auto;
border: none;
border-radius: 0;
transform: none;
transform-origin: 0 0
}
.wux-dialog__button--default {
color: #444!important
}
.wux-dialog__button--primary {
color: #33cd5f!important
}
.wux-dialog__button--bold {
font-weight: 500!important
}
.wux-dialog__button--hover {
background-color: #ececec!important
}
.wux-dialog__button--disabled {
opacity: .3
}
.wux-dialog__prompt {
position: relative;
margin-top: 20rpx
}
.wux-dialog__prompt::after {
content: " ";
position: absolute;
top: 0;
left: 0;
width: 200%;
height: 200%;
transform: scale(.5);
transform-origin: 0 0;
pointer-events: none;
box-sizing: border-box;
border: 0 solid #d9d9d9;
border-top-width: 1PX;
border-right-width: 1PX;
border-bottom-width: 1PX;
border-left-width: 1PX;
border-radius: 12rpx
}
.wux-dialog__input {
padding: 8rpx 12rpx;
height: 72rpx;
line-height: 1;
width: 100%;
text-align: left;
box-sizing: border-box
}
.wux-dialog__buttons {
display: -ms-flexbox;
display: flex;
-ms-flex: 1;
flex: 1
}
.wux-dialog__buttons--horizontal .wux-dialog__button::after {
content: " ";
position: absolute;
left: 0;
top: 0;
width: 1PX;
bottom: 0;
border-left: 1PX solid #d9d9d9;
color: #d9d9d9;
transform-origin: 0 0;
transform: scaleX(.5)
}
.wux-dialog__buttons--horizontal .wux-dialog__button:first-child::after {
display: none
}
.wux-dialog__buttons--vertical {
display: block;
height: auto
}
.wux-dialog__buttons--vertical .wux-dialog__button::after {
content: " ";
position: absolute;
left: 0;
top: 0;
right: 0;
height: 1PX;
border-top: 1PX solid #d9d9d9;
color: #d9d9d9;
transform-origin: 0 0;
transform: scaleY(.5)
}