<template>
  <div>
    <button @click='sendSMS'>发送短信</button>
    <button @click='setEmergencyContact'>设置紧急联系人号码</button>
  </div>
</template>
<script>
export default {
  methods: {
    sendSMS() {
      uni.showModal({
        title: '提示',
        content: '确定发送短信吗?',
        success: (res) => {
          if (res.confirm) {
            uni.getLocation({
              success: (res) => {
                const location = `我的位置是:经度${res.longitude},纬度${res.latitude}`
                uni.sendSMS({
                  phoneNumber: '111',
                  message: location,
                  success: () => {
                    uni.showToast({
                      title: '发送成功',
                      icon: 'success'
                    })
                  },
                  fail: () => {
                    uni.showToast({
                      title: '发送失败',
                      icon: 'none'
                    })
                  }
                })
              },
              fail: () => {
                uni.showToast({
                  title: '获取位置信息失败',
                  icon: 'none'
                })
              }
            })
          }
        }
      })
    },
    setEmergencyContact() {
      // 设置紧急联系人号码的逻辑
      uni.showActionSheet({
        title: '请选择设置方式',
        itemList: ['手动输入', '从通讯录选择'],
        success: (res) => {
          if (res.tapIndex === 0) {
            // 手动输入号码
            uni.prompt({
              title: '请输入紧急联系人号码',
              success: (res) => {
                if (res.confirm) {
                  // 保存号码
                  console.log('输入的号码:', res.content);
                }
              }
            });
          } else if (res.tapIndex === 1) {
            // 从通讯录选择
            uni.chooseContact({
              success: (res) => {
                // 保存号码
                console.log('选择的联系人:', res.contact);
              }
            });
          }
        }
      });
    }
  }
}
</script>
一键发送位置短信,紧急联系人设置指南

原文地址: https://www.cveoy.top/t/topic/g5Ci 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录