|
1 | 1 | <template> |
2 | | - <view> |
3 | | - <page-head :title="title"></page-head> |
4 | | - <view class="uni-common-mt"> |
5 | | - <view class="uni-list"> |
6 | | - <view class="uni-list-cell"> |
7 | | - <view class="uni-list-cell-left"> |
8 | | - <view class="uni-label">名称</view> |
9 | | - </view> |
10 | | - <view class="uni-list-cell-db"> |
11 | | - <input class="uni-input" type="text" placeholder="请输入联系人名称" name="name" :value="name" @input="nameChange"></input> |
12 | | - </view> |
13 | | - </view> |
14 | | - <view class="uni-list-cell"> |
15 | | - <view class="uni-list-cell-left"> |
16 | | - <view class="uni-label">手机号</view> |
17 | | - </view> |
18 | | - <view class="uni-list-cell-db"> |
19 | | - <input class="uni-input" type="text" placeholder="请输入联系人手机号" name="phone" :value="phone" @input="phoneChange"></input> |
20 | | - </view> |
21 | | - </view> |
22 | | - </view> |
23 | | - <view class="uni-padding-wrap"> |
24 | | - <view class="uni-btn-v"> |
25 | | - <button type="primary" class="btn-setstorage" @tap="add">添加联系人</button> |
26 | | - </view> |
27 | | - </view> |
28 | | - </view> |
29 | | - </view> |
| 2 | + <view> |
| 3 | + <page-head :title="title"></page-head> |
| 4 | + <view class="uni-common-mt"> |
| 5 | + <view class="uni-list"> |
| 6 | + <view class="uni-list-cell"> |
| 7 | + <view class="uni-list-cell-left"> |
| 8 | + <view class="uni-label">名称</view> |
| 9 | + </view> |
| 10 | + <view class="uni-list-cell-db"> |
| 11 | + <input class="uni-input" type="text" placeholder="请输入联系人名称" name="name" :value="name" @input="nameChange"></input> |
| 12 | + </view> |
| 13 | + </view> |
| 14 | + <view class="uni-list-cell"> |
| 15 | + <view class="uni-list-cell-left"> |
| 16 | + <view class="uni-label">手机号</view> |
| 17 | + </view> |
| 18 | + <view class="uni-list-cell-db"> |
| 19 | + <input class="uni-input" type="text" placeholder="请输入联系人手机号" name="phone" :value="phone" @input="phoneChange"></input> |
| 20 | + </view> |
| 21 | + </view> |
| 22 | + </view> |
| 23 | + <view class="uni-padding-wrap"> |
| 24 | + <view class="uni-btn-v"> |
| 25 | + <button type="primary" class="btn-setstorage" @tap="add">添加联系人</button> |
| 26 | + </view> |
| 27 | + </view> |
| 28 | + </view> |
| 29 | + </view> |
30 | 30 | </template> |
31 | 31 | <script> |
32 | | - import permision from "@/common/permission.js" |
33 | | - export default { |
34 | | - data() { |
35 | | - return { |
36 | | - title: 'addPhoneContact', |
37 | | - name: '', |
38 | | - phone: '' |
39 | | - } |
40 | | - }, |
41 | | - methods: { |
42 | | - nameChange: function(e) { |
43 | | - this.name = e.detail.value |
44 | | - }, |
45 | | - phoneChange: function(e) { |
46 | | - this.phone = e.detail.value |
47 | | - }, |
48 | | - add() { |
49 | | - // #ifdef APP-PLUS |
50 | | - if (this.checkPermission() !== 1) { |
51 | | - return; |
52 | | - } |
53 | | - // #endif |
| 32 | + // #ifdef APP-PLUS |
| 33 | + import permision from "@/common/permission.js" |
| 34 | + // #endif |
| 35 | + export default { |
| 36 | + data() { |
| 37 | + return { |
| 38 | + title: 'addPhoneContact', |
| 39 | + name: '', |
| 40 | + phone: '' |
| 41 | + } |
| 42 | + }, |
| 43 | + methods: { |
| 44 | + nameChange: function(e) { |
| 45 | + this.name = e.detail.value |
| 46 | + }, |
| 47 | + phoneChange: function(e) { |
| 48 | + this.phone = e.detail.value |
| 49 | + }, |
| 50 | + add() { |
| 51 | + // #ifdef APP-PLUS |
| 52 | + if (this.checkPermission() !== 1) { |
| 53 | + return; |
| 54 | + } |
| 55 | + // #endif |
54 | 56 |
|
55 | | - uni.addPhoneContact({ |
56 | | - firstName: this.name, |
57 | | - mobilePhoneNumber: this.phone, |
58 | | - success: function() { |
59 | | - uni.showModal({ |
60 | | - content: '已成功添加联系人!', |
61 | | - showCancel: false |
62 | | - }) |
63 | | - }, |
64 | | - fail: function() { |
65 | | - uni.showModal({ |
66 | | - content: '添加联系人失败!', |
67 | | - showCancel: false |
68 | | - }) |
69 | | - } |
70 | | - }); |
71 | | - } |
72 | | - // #ifdef APP-PLUS |
73 | | - , |
74 | | - async checkPermission() { |
75 | | - let status = permision.isIOS ? await permision.requestIOS('contact') : |
76 | | - await permision.requestAndroid('android.permission.WRITE_CONTACTS'); |
| 57 | + uni.addPhoneContact({ |
| 58 | + firstName: this.name, |
| 59 | + mobilePhoneNumber: this.phone, |
| 60 | + success: function() { |
| 61 | + uni.showModal({ |
| 62 | + content: '已成功添加联系人!', |
| 63 | + showCancel: false |
| 64 | + }) |
| 65 | + }, |
| 66 | + fail: function() { |
| 67 | + uni.showModal({ |
| 68 | + content: '添加联系人失败!', |
| 69 | + showCancel: false |
| 70 | + }) |
| 71 | + } |
| 72 | + }); |
| 73 | + } |
| 74 | + // #ifdef APP-PLUS |
| 75 | + , |
| 76 | + async checkPermission() { |
| 77 | + let status = permision.isIOS ? await permision.requestIOS('contact') : |
| 78 | + await permision.requestAndroid('android.permission.WRITE_CONTACTS'); |
77 | 79 |
|
78 | | - if (status === null || status === 1) { |
79 | | - status = 1; |
80 | | - } else { |
81 | | - uni.showModal({ |
82 | | - content: "需要联系人权限", |
83 | | - confirmText: "设置", |
84 | | - success: function(res) { |
85 | | - if (res.confirm) { |
86 | | - permision.gotoAppSetting(); |
87 | | - } |
88 | | - } |
89 | | - }) |
90 | | - } |
91 | | - return status; |
92 | | - } |
93 | | - // #endif |
94 | | - } |
95 | | - } |
| 80 | + if (status === null || status === 1) { |
| 81 | + status = 1; |
| 82 | + } else { |
| 83 | + uni.showModal({ |
| 84 | + content: "需要联系人权限", |
| 85 | + confirmText: "设置", |
| 86 | + success: function(res) { |
| 87 | + if (res.confirm) { |
| 88 | + permision.gotoAppSetting(); |
| 89 | + } |
| 90 | + } |
| 91 | + }) |
| 92 | + } |
| 93 | + return status; |
| 94 | + } |
| 95 | + // #endif |
| 96 | + } |
| 97 | + } |
96 | 98 | </script> |
97 | 99 |
|
98 | 100 | <style> |
|
0 commit comments