123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- const app = getApp()
- import {
- throttle,
- getWaterDrop
- } from '../../utils/index/index'
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- isVisible: {
- type: Boolean,
- value: false,
- observer: "handleVisibilityChange"
- }
- },
- props: {
- // 是否显示modal
- visible: {
- type: Boolean,
- value: false
- },
- // 自定义内容
- content: {
- type: String,
- value: ''
- },
- // 是否显示取消按钮(默认显示)
- // showCancelBtn: true,
- showCancelBtn: { // 定义一个属性
- type: Boolean,
- value: true, // 默认值
- observer(newVal, oldVal) {
- // 属性变化监听器
- console.log('myProperty changed from', oldVal, 'to', newVal);
- this.updateValue(newVal);
- }
- },
- // 是否显示确认按钮(默认不显示)
- showOkBtn: true,
- //取消按钮文本
- cancelText: '取消',
- //确认按钮文本
- okText: '确认',
- //取消按钮回调
- onCancel: {
- type: Function,
- value: () => {}
- },
- //确认按钮回调
- onOk: {
- type: Function,
- value: () => {}
- },
- },
- /**
- * 组件的初始数据
- */
- data: {
- btnStatus: true,
- },
- lifetimes: {
- attached() {
- // 初始化时手动调用
- this.handleVisibilityChange(this.data.isVisible);
- }
- },
- didMount() {
- console.log(this.props.showCancelBtn)
- },
- didUpdate(newVal, oldVal) {
- console.log('didUpdate', newVal, oldVal)
- console.log(this.props.showCancelBtn)
- },
- /**
- * 组件的方法列表
- */
- methods: {
- handleVisibilityChange(isVisible) {
- console.log("Visibility on load:", isVisible);
- },
- updateValue(newVal) {
- console.log(newVal)
- // 更新内部数据或执行其他逻辑
- this.setData({
- btnStatus: newVal
- });
- },
- cancel: throttle( function () {
- setTimeout(()=>{
- this.props.onCancel();
- }, 100)
- }, 1000),
- confirm: throttle( function () {
- setTimeout(()=>{
- this.props.onOk();
- }, 100)
- }, 1000),
- },
- observers: {}
- })
|