Browse Source

小程序:登录

panyong 2 years ago
parent
commit
6e95f59bd4

+ 88 - 7
htmldev/wxMini/pages/contactBusiness/contactBusiness.js

@@ -7,15 +7,21 @@ Page({
     booShow: false,
     actions: [
       {
-        name: '呼叫'
+        name: '呼叫',
+        value: 'makePhoneCall'
       },
       {
-        name: '复制号码'
+        name: '复制号码',
+        value: 'setClipboardData'
       },
       {
-        name: '添加到手机通讯录'
+        name: '添加到手机通讯录',
+        value: 'addPhoneContact'
       }
-    ]
+    ],
+    businessInfo: {
+      phone: '13429176706'
+    }
   },
 
   /**
@@ -79,8 +85,83 @@ Page({
   hideActionSheet() {
     this.setData({ booShow: false })
   },
-
-  onSelect(event) {
-    console.log(event.detail)
+  async onSelect(event) {
+    const { value } = event.detail
+    const { businessInfo } = this.data
+    this.hideActionSheet()
+    switch (value) {
+      case 'makePhoneCall':
+        try {
+          await wx.makePhoneCall({ phoneNumber: businessInfo.phone })
+        } catch (err) {}
+        break
+      case 'setClipboardData':
+        try {
+          await wx.setClipboardData({ data: businessInfo.phone })
+        } catch (err) {}
+        break
+      case 'addPhoneContact':
+        this.handleGetSetting()
+        break
+      default:
+    }
+  },
+  // 获取添加手机通讯录联系人权限
+  async handleGetSetting() {
+    const that = this
+
+    try {
+      const { errMsg, authSetting } = await wx.getSetting()
+      if (errMsg === 'getSetting:ok') {
+        if (authSetting['scope.addPhoneContact']) {
+          await that.addPhoneContactBridge()
+          return
+        }
+      }
+    } catch (err) {}
+
+    try {
+      await wx.authorize({ scope: 'scope.addPhoneContact' })
+      await that.addPhoneContactBridge()
+    } catch (err) {
+      wx.showModal({
+        title: '提示',
+        content: '未开启添加手机通讯录联系人权限,去设置中打开',
+        success(res) {
+          if (res.confirm) {
+            that.openSetting()
+          }
+        }
+      })
+    }
+  },
+  // 去小程序自带设置页:返回
+  async openSetting() {
+    try {
+      const openSettingData = await wx.openSetting()
+      if (openSettingData.authSetting['scope.addPhoneContact']) {
+        await this.addPhoneContactBridge()
+      }
+    } catch (err) {}
+  },
+  async addPhoneContactBridge() {
+    const { businessInfo } = this.data
+
+    try {
+      await wx.addPhoneContact({
+        firstName: 'businessInfo.phone',
+        mobilePhoneNumber: businessInfo.phone
+      })
+    } catch (err) {}
+  },
+  async openLocationBridge() {
+    try {
+      // 测试 latitude: 30.25727 longitude: 120.20523
+      await wx.openLocation({
+        latitude: 30.25727,
+        longitude: 120.20523,
+        name: '浙江省杭州市余杭区'
+      })
+    } catch (err) {}
   }
 })

+ 3 - 1
htmldev/wxMini/pages/contactBusiness/contactBusiness.wxml

@@ -40,7 +40,9 @@
   </view>
   <view class="business-info">
     <view class="label">商家信息</view>
-    <view class="value">
+    <view
+      class="value"
+      bind:tap="openLocationBridge">
       <image class="icon-map" src=""></image>
       <view class="address-wrap">
         <view class="address">地址:浙江省杭州市余杭区道浙江省杭州市余杭区道浙江省杭州市余杭区道浙江省杭州市余杭区道