小程序常用实用例子

拍照

// 选择照片

ChooseImage() {

wx.chooseImage({

count: 4, //默认9

sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有

sourceType: ['album'], //从相册选择

success: (res) => {

if (this.data.imgList.length != 0) {

this.setData({

imgList: this.data.imgList.concat(res.tempFilePaths)

})

} else {

this.setData({

imgList: res.tempFilePaths

})

}

}

});

},

页面

<view class="solids" bindtap="ChooseImage" wx:if="{{imgList.length<4}}">

<text class="cuIcon-cameraadd"></text>

</view>

照片预览

<view class="bg-img" wx:for="{{imgList}}" wx:key="index" bindtap="ViewImage" data-url="{{imgList[index]}}">

<image src='{{imgList[index]}}' mode='aspectFill'></image>

<view class="cu-tag bg-red" catchtap="DelImg" data-index="{{index}}">

<text class="cuIcon-close"></text>

</view>

</view>

// 预览照片

ViewImage(e) {

wx.previewImage({

urls: this.data.imgList,

current: e.currentTarget.dataset.url

});

},

// 打电话

CallPhone(e) {

console.log(e, e.currentTarget.dataset.phone)

let phoneNumber = e.currentTarget.dataset.phone

let showphone = e.currentTarget.dataset.showphone

wx.showModal({

title: '温馨提示',

content: `是否拨打${showphone}号码?`,

confirmText: '确定拨打',

confirmColor: '#0081ff',

cancelText: '取消',

cancelColor: '#acb5bd',

success: res => {

console.log(res)

if (res.confirm) {

wx.makePhoneCall({

phoneNumber: phoneNumber,

success: res => {

console.log(res)

},

fail: err => {

console.log(err)

}

})

}

},

fail: err => {

console.log(err)

}

})

},

相关推荐
中小企业实战军师刘孙亮8 小时前
实体店的小程序转型之路:拥抱新零售的密码-中小企实战运营和营销工作室博客
职场和发展·小程序·创业创新·学习方法·业界资讯·零售·内容运营
说私域9 小时前
基于开源技术体系的品牌赛道力重构:AI智能名片与S2B2C商城小程序源码驱动的品类创新机制研究
人工智能·小程序·重构·开源·零售
王哈哈的学习笔记10 小时前
uniapp小程序使用echarts
前端·小程序·uni-app
说私域15 小时前
颠覆传统微商!开源AI智能名片链动2+1模式S2B2C商城小程序:重构社交电商的“降维打击”革命
人工智能·小程序·开源·零售
ai大佬16 小时前
我是如何用AI编程制作一个AI表情包生成的小程序
人工智能·小程序·ai编程·api中转·apikey
Maitians17 小时前
微信小程序 - 根据经纬度打开导航
微信小程序·小程序
xuanjiong19 小时前
微信小程序,基于uni-app的轮播图制作,调用文件中图片
微信小程序·小程序·uni-app
天_真好1 天前
小程序知识点总结1
小程序
gurenchang1 天前
实现从一个微信小程序跳转到另一个微信小程序
微信小程序·小程序
编程毕设1 天前
【含文档+PPT+源码】基于微信小程序的校园快递平台
微信小程序·小程序