12 |
IconFont 图标
13 |
14 |
15 | -
16 |
17 |
搜索
18 | .icon-sousuo
19 |
20 |
21 | -
22 |
23 |
名片
24 | .icon-card
25 |
26 |
27 | -
28 |
29 |
时间
30 | .icon-shijian
31 |
32 |
33 | -
34 |
35 |
A
36 | .icon-letter-a-outline
37 |
38 |
39 | -
40 |
41 |
设置
42 | .icon-shezhi
43 |
44 |
45 | -
46 |
47 |
勾选
48 | .icon-gouxuan
49 |
50 |
51 | -
52 |
53 |
定位
54 | .icon-location
55 |
56 |
57 | -
58 |
59 |
打钩
60 | .icon-dagou
61 |
62 |
63 | -
64 |
65 |
下拉
66 | .icon-xiala
67 |
68 |
69 | -
70 |
71 |
访客预约
72 | .icon-fangkeyuyue
73 |
74 |
75 | -
76 |
77 |
登录_手机验证
78 | .icon-shoujiyanzheng
79 |
80 |
81 | -
82 |
83 |
我的
84 | .icon-user
85 |
86 |
87 | -
88 |
89 |
电话
90 | .icon-dianhua
91 |
92 |
93 | -
94 |
95 |
朋友圈
96 | .icon-icon1460188600932
97 |
98 |
99 | -
100 |
101 |
名片
102 | .icon-mingpian-copy
103 |
104 |
105 | -
106 |
107 |
默认
108 | .icon-moren
109 |
110 |
111 | -
112 |
113 |
邮箱
114 | .icon-youxiang
115 |
116 |
117 | -
118 |
119 |
部门
120 | .icon-bumen
121 |
122 |
123 | -
124 |
125 |
组
126 | .icon-zu
127 |
128 |
129 | -
130 |
131 |
足迹
132 | .icon-zuji
133 |
134 |
135 | -
136 |
137 |
验证
138 | .icon-yanzheng
139 |
140 |
141 | -
142 |
143 |
名片夹
144 | .icon-mingpianjia1
145 |
146 |
147 | -
148 |
149 |
搜索_搜索
150 | .icon-sousuo_sousuo
151 |
152 |
153 | -
154 |
155 |
关于
156 | .icon-guanyu
157 |
158 |
159 | -
160 |
161 |
右侧小程序二维码
162 | .icon-youcexiaochengxuerweima
163 |
164 |
165 | -
166 |
167 |
小程序
168 | .icon-xiaochengxu
169 |
170 |
171 | -
172 |
173 |
中英文切换-显示中英文
174 | .icon-zhongyingwenqiehuan-xianshizhongyingwen
175 |
176 |
177 | -
178 |
179 |
arrows_circle_minus
180 | .icon-arrows_circle_minus
181 |
182 |
183 | -
184 |
185 |
arrows_circle_plus
186 | .icon-arrows_circle_plus
187 |
188 |
189 | -
190 |
191 |
公司
192 | .icon-gongsi
193 |
194 |
195 | -
196 |
197 |
angle-right
198 | .icon-angle-right
199 |
200 |
201 | -
202 |
203 |
angle-left
204 | .icon-angle-left
205 |
206 |
207 | -
208 |
209 |
arrows_circle_remove
210 | .icon-arrows_circle_remove1
211 |
212 |
213 |
214 |
215 |
font-class引用
216 |
217 |
218 |
font-class是unicode使用方式的一种变种,主要是解决unicode书写不直观,语意不明确的问题。
219 |
与unicode使用方式相比,具有如下特点:
220 |
221 | - 兼容性良好,支持ie8+,及所有现代浏览器。
222 | - 相比于unicode语意明确,书写更直观。可以很容易分辨这个icon是什么。
223 | - 因为使用class来定义图标,所以当要替换图标时,只需要修改class里面的unicode引用。
224 | - 不过因为本质上还是使用的字体,所以多色图标还是不支持的。
225 |
226 |
使用步骤如下:
227 |
第一步:引入项目下面生成的fontclass代码:
228 |
229 |
230 |
231 |
第二步:挑选相应图标并获取类名,应用于页面:
232 |
<i class="iconfont icon-xxx"></i>
233 |
234 | "iconfont"是你项目下的font-family。可以通过编辑项目查看,默认是"iconfont"。
235 |
236 |
237 |
238 |
239 |
--------------------------------------------------------------------------------
/pages/carddetails/carddetails.js:
--------------------------------------------------------------------------------
1 | // pages/carddetails/carddetails.js
2 | //获取应用实例
3 | var app = getApp()
4 |
5 | Page({
6 | data: {
7 | mobile: '',
8 | getData: {},
9 | isshare: false,
10 | isviewImage: true,
11 | econds: 3,
12 | cardDetailsData: {},
13 | removeCollCard: {
14 | 'url': 'Card/removeCollCard',
15 | 'data': {
16 | 'id': ''
17 | }
18 | },
19 | GetOthersCard2: {
20 | 'url': 'https://api.91ygj.com/vCard/Card/GetOthersCard2',
21 | 'data': {
22 | 'id': ''
23 | }
24 | },
25 | CardShareData: {
26 | 'url': 'Card/GetCardShared',
27 | 'data': {
28 | 'id': ''
29 | }
30 | },
31 | cardDetails: {
32 | 'url': 'Card/GetCard',
33 | 'data': {
34 | 'id': ''
35 | }
36 | },
37 | othersCardDetails: {
38 | 'url': 'Card/GetOthersCard',
39 | 'data': {
40 | 'id': ''
41 | }
42 | },
43 | collCardData: {
44 | 'url': 'Card/CollCard',
45 | 'data': {
46 | 'id': ''
47 | }
48 | },
49 | GetCardQRCode: {
50 | 'url': 'Card/GetCardQRCode',
51 | 'data': {
52 | 'id': ''
53 | }
54 | }
55 | },
56 | //打开地图
57 | openAddress: function (e) {
58 | wx.getLocation({
59 | //返回可以用于wx.openLocation的经纬度
60 | success: function (res) {
61 | var latitude = parseFloat(e.target.dataset.loglat.split(",")[0])
62 | var longitude = parseFloat(e.target.dataset.loglat.split(",")[1])
63 | wx.openLocation({
64 | latitude: latitude,
65 | longitude: longitude,
66 | name: e.target.dataset.name,
67 | address: e.target.dataset.name,
68 | scale: 28,
69 | complete: function (res) {
70 | }
71 | })
72 | }
73 | })
74 | },
75 | onShareAppMessage: function () {
76 | var that = this
77 | return {
78 | title: '您好,这是我的名片,请惠存。',
79 | path: 'pages/carddetails/carddetails?id=' + that.data.cardDetails.data.id + '&share=1',
80 | success: function (res) {
81 | // 分享成功
82 | },
83 | fail: function (res) {
84 | // 分享失败
85 | }
86 | }
87 | },
88 | //拨打电话
89 | phoneCall: function (e) {
90 | wx.makePhoneCall({
91 | phoneNumber: e.target.dataset.id //仅为示例,并非真实的电话号码
92 | })
93 | },
94 | countdown: function (that) {
95 | var second = that.data.econds
96 | var timer
97 | if (second == 0) {
98 | clearTimeout(timer);
99 | that.setData({
100 | econds: 3,
101 | isviewImage: true
102 | });
103 | return;
104 | }
105 | timer = setTimeout(function () {
106 | that.setData({
107 | econds: second - 1,
108 | isviewImage: false
109 | });
110 | that.countdown(that);
111 | }, 1000)
112 | },
113 | //获取二维码地址
114 | getCode: function (e) {
115 | var that = this
116 | that.setData({
117 | 'GetCardQRCode.data.id': e.currentTarget.dataset.id
118 | })
119 | app.postData(that.data.GetCardQRCode, function (res) {
120 | wx.previewImage({
121 | current: res.data + '?' + Math.random(),
122 | urls: [res.data + '?' + Math.random()],
123 | success: function () {
124 | that.countdown(that);
125 | }
126 | })
127 | })
128 | },
129 | //删除单张名片
130 | removeCard: function (e) {
131 | var data = {
132 | 'url': 'Card/RemoveCard',
133 | 'data': {
134 | 'id': e.target.dataset.id
135 | }
136 | }
137 | app.postData(data, function (res) {
138 | wx.showToast({
139 | title: res.msg,
140 | icon: 'success',
141 | duration: 2000,
142 | complete: function () {
143 | wx.navigateBack({
144 | delta: 1
145 | })
146 | }
147 | })
148 | })
149 | },
150 | //编辑单张名片
151 | editCard: function (e) {
152 | wx.navigateTo({
153 | url: '../createcard/createcard?id=' + e.target.dataset.id
154 | })
155 | },
156 | //设置单张默认名片
157 | setCardDefault: function (e) {
158 | var that = this
159 | var data = {
160 | 'url': 'Card/SetCardDefault',
161 | 'data': {
162 | 'id': e.target.dataset.id
163 | }
164 | }
165 | app.postData(data, function (res) {
166 | wx.showToast({
167 | title: res.msg,
168 | icon: 'success',
169 | duration: 2000,
170 | complete: function () {
171 | app.postData(that.data.cardDetails, function (res) {
172 | that.setData({
173 | cardDetailsData: res.data
174 | })
175 | })
176 | }
177 | })
178 | })
179 | },
180 | //打开我的名片
181 | openMycard: function () {
182 | wx.switchTab({
183 | url: '../mycard/mycard'
184 | })
185 | },
186 | //移除收藏的名片
187 | undockCard: function (e) {
188 | var that = this
189 | that.setData({
190 | 'removeCollCard.data.id': e.target.dataset.id
191 | })
192 | app.postData(that.data.removeCollCard, function (res) {
193 | wx.showToast({
194 | title: res.msg,
195 | icon: 'success',
196 | duration: 2000,
197 | complete: function () {
198 | app.postData(that.data.othersCardDetails, function (res) {
199 | that.setData({
200 | cardDetailsData: res.data
201 | })
202 | })
203 | }
204 | })
205 | })
206 | },
207 | //收藏他人名片夹
208 | addCard: function (e) {
209 | var that = this
210 | that.setData({
211 | 'collCardData.data.id': e.target.dataset.id
212 | })
213 | app.postData(that.data.collCardData, function (res) {
214 | wx.showToast({
215 | title: res.msg,
216 | icon: 'success',
217 | duration: 2000,
218 | complete: function () {
219 | // wx.switchTab({
220 | // url: '../mycard/mycard'
221 | // })
222 | app.postData(that.data.othersCardDetails, function (res) {
223 | that.setData({
224 | cardDetailsData: res.data
225 | })
226 | })
227 | }
228 | })
229 | })
230 | },
231 | //收藏他人名片夹 并且打开名片小程序
232 | addCardOpen: function (e) {
233 | var that = this
234 | that.setData({
235 | 'collCardData.data.id': e.target.dataset.id
236 | })
237 | app.postData(that.data.collCardData, function (res) {
238 | wx.showToast({
239 | title: res.msg,
240 | icon: 'success',
241 | duration: 2000,
242 | complete: function () {
243 | wx.switchTab({
244 | url: '../cardcase/cardcase'
245 | })
246 | }
247 | })
248 | })
249 | },
250 | openShare: function (e) {
251 | var that = this
252 | that.setData({
253 | 'CardShareData.data.id': e.target.dataset.id
254 | })
255 | app.postData(that.data.CardShareData, function (res) {
256 | wx.previewImage({
257 | current: res.data + '?' + Math.random(), // 当前显示图片的http链接
258 | urls: [res.data + '?' + Math.random()] // 需要预览的图片http链接列表
259 | })
260 | that.setData({
261 | isviewImage: true
262 | })
263 | })
264 | },
265 | onLoad: function (options) {
266 | // 页面初始化 options为页面跳转所带来的参数
267 | var that = this
268 | if (options.q) {
269 | var src = decodeURIComponent(options.q)
270 |
271 | console.log(options.q)
272 | src.match(/id=(\S*)&share=1/)[1]
273 | that.setData({
274 | 'cardDetails.data.id': src.match(/id=(\S*)&share=1/)[1],
275 | 'othersCardDetails.data.id': src.match(/id=(\S*)&share=1/)[1],
276 | 'GetOthersCard2.data.id': src.match(/id=(\S*)&share=1/)[1]
277 | })
278 | app.getLogiCallback('', function () {
279 | wx.request({
280 | url: that.data.GetOthersCard2.url,
281 | method: 'POST',
282 | data: that.data.GetOthersCard2.data,
283 | header: {
284 | 'token': wx.getStorageSync('loginSuccessData').token,
285 | 'content-type': 'application/json'
286 | },
287 | success: function (res) {
288 | that.setData({
289 | isshare: true,
290 | cardDetailsData: res.data.data,
291 | mobile: wx.getStorageSync('loginSuccessData').mobile
292 | })
293 | },
294 | fail: function (res) {
295 | console.log('请求出错')
296 | }
297 | })
298 | })
299 | } else {
300 | that.setData({
301 | 'cardDetails.data.id': options.id,
302 | 'othersCardDetails.data.id': options.id,
303 | 'GetOthersCard2.data.id': options.id
304 | })
305 | if (options.share) {
306 | app.getLogiCallback('', function () {
307 | wx.request({
308 | url: that.data.GetOthersCard2.url,
309 | method: 'POST',
310 | data: that.data.GetOthersCard2.data,
311 | header: {
312 | 'token': wx.getStorageSync('loginSuccessData').token,
313 | 'content-type': 'application/json'
314 | },
315 | success: function (res) {
316 | that.setData({
317 | isshare: true,
318 | cardDetailsData: res.data.data,
319 | mobile: wx.getStorageSync('loginSuccessData').mobile
320 | })
321 | },
322 | fail: function (res) {
323 | console.log('请求出错')
324 | }
325 | })
326 | })
327 | } else {
328 | if (options.type) {
329 | that.setData({
330 | getData: that.data.othersCardDetails,
331 | })
332 | } else {
333 | that.setData({
334 | getData: that.data.cardDetails,
335 | })
336 | }
337 | app.postData(that.data.getData, function (res) {
338 | that.setData({
339 | cardDetailsData: res.data,
340 | mobile: wx.getStorageSync('loginSuccessData').mobile
341 | })
342 |
343 | wx.setNavigationBarTitle({
344 | title: res.data.name
345 | })
346 | })
347 | }
348 | }
349 | },
350 | onReady: function () {
351 | // 页面渲染完成
352 | },
353 | onShow: function () {
354 | // 页面显示
355 | if (wx.getStorageSync('token')) {
356 | var that = this
357 | app.postData(that.data.getData, function (res) {
358 | that.setData({
359 | cardDetailsData: res.data,
360 | mobile: wx.getStorageSync('loginSuccessData').mobile
361 | })
362 | })
363 | }
364 | },
365 | onHide: function () {
366 | // 页面隐藏
367 | },
368 | onUnload: function () {
369 | // 页面关闭
370 | }
371 | })
--------------------------------------------------------------------------------
/pages/cardcase/cardcase.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
32 |
IconFont 图标
33 |
34 |
35 | -
36 |
37 |
搜索
38 | 
39 |
40 |
41 | -
42 |
43 |
名片
44 | 
45 |
46 |
47 | -
48 |
49 |
时间
50 | 
51 |
52 |
53 | -
54 |
55 |
A
56 | 
57 |
58 |
59 | -
60 |
61 |
设置
62 | 
63 |
64 |
65 | -
66 |
67 |
勾选
68 | 
69 |
70 |
71 | -
72 |
73 |
定位
74 | 
75 |
76 |
77 | -
78 |
79 |
打钩
80 | 
81 |
82 |
83 | -
84 |
85 |
下拉
86 | 
87 |
88 |
89 | -
90 |
91 |
访客预约
92 | 
93 |
94 |
95 | -
96 |
97 |
登录_手机验证
98 | 
99 |
100 |
101 | -
102 |
103 |
我的
104 | 
105 |
106 |
107 | -
108 |
109 |
电话
110 | 
111 |
112 |
113 | -
114 |
115 |
朋友圈
116 | 
117 |
118 |
119 | -
120 |
121 |
名片
122 | 
123 |
124 |
125 | -
126 |
127 |
默认
128 | 
129 |
130 |
131 | -
132 |
133 |
邮箱
134 | 
135 |
136 |
137 | -
138 |
139 |
部门
140 | 
141 |
142 |
143 | -
144 |
145 |
组
146 | 
147 |
148 |
149 | -
150 |
151 |
足迹
152 | 
153 |
154 |
155 | -
156 |
157 |
验证
158 | 
159 |
160 |
161 | -
162 |
163 |
名片夹
164 | 
165 |
166 |
167 | -
168 |
169 |
搜索_搜索
170 | 
171 |
172 |
173 | -
174 |
175 |
关于
176 | 
177 |
178 |
179 | -
180 |
181 |
右侧小程序二维码
182 | 
183 |
184 |
185 | -
186 |
187 |
小程序
188 | 
189 |
190 |
191 | -
192 |
193 |
中英文切换-显示中英文
194 | 
195 |
196 |
197 | -
198 |
199 |
arrows_circle_minus
200 | 
201 |
202 |
203 | -
204 |
205 |
arrows_circle_plus
206 | 
207 |
208 |
209 | -
210 |
211 |
公司
212 | 
213 |
214 |
215 | -
216 |
217 |
angle-right
218 | 
219 |
220 |
221 | -
222 |
223 |
angle-left
224 | 
225 |
226 |
227 | -
228 |
229 |
arrows_circle_remove
230 | 
231 |
232 |
233 |
234 |
unicode引用
235 |
236 |
237 |
unicode是字体在网页端最原始的应用方式,特点是:
238 |
239 | - 兼容性最好,支持ie6+,及所有现代浏览器。
240 | - 支持按字体的方式去动态调整图标大小,颜色等等。
241 | - 但是因为是字体,所以不支持多色。只能使用平台里单色的图标,就算项目里有多色图标也会自动去色。
242 |
243 |
244 | 注意:新版iconfont支持多色图标,这些多色图标在unicode模式下将不能使用,如果有需求建议使用symbol的引用方式
245 |
246 |
unicode使用步骤如下:
247 |
第一步:拷贝项目下面生成的font-face
248 |
@font-face {
249 | font-family: 'iconfont';
250 | src: url('iconfont.eot');
251 | src: url('iconfont.eot?#iefix') format('embedded-opentype'),
252 | url('iconfont.woff') format('woff'),
253 | url('iconfont.ttf') format('truetype'),
254 | url('iconfont.svg#iconfont') format('svg');
255 | }
256 |
257 |
第二步:定义使用iconfont的样式
258 |
.iconfont{
259 | font-family:"iconfont" !important;
260 | font-size:16px;font-style:normal;
261 | -webkit-font-smoothing: antialiased;
262 | -webkit-text-stroke-width: 0.2px;
263 | -moz-osx-font-smoothing: grayscale;
264 | }
265 |
266 |
第三步:挑选相应图标并获取字体编码,应用于页面
267 |
<i class="iconfont">3</i>
268 |
269 |
270 | "iconfont"是你项目下的font-family。可以通过编辑项目查看,默认是"iconfont"。
271 |
272 |
273 |
274 |
275 |
276 |
277 |
--------------------------------------------------------------------------------
/pages/createcard/createcard.js:
--------------------------------------------------------------------------------
1 | // pages/createcard/createcard.js
2 | //获取应用实例
3 | var app = getApp()
4 |
5 | Page({
6 | data: {
7 | iseng: true,
8 | ischinese: true,
9 | isen: false,
10 | cardData: {
11 | "url": "",
12 | 'data': {
13 | 'id': '',
14 | 'name': '',
15 | 'title': '',
16 | 'mobile': '',
17 | 'companyName': '',
18 | 'more': '',
19 | 'mobileVerify': false,
20 | 'avatarUrl': '',
21 | 'isDefault': false,
22 | 'email': '',
23 | 'address': '',
24 | 'loglat': '',
25 | 'language': ''
26 | }
27 | },
28 | enCardData: {
29 | "url": "",
30 | 'data': {
31 | 'id': '',
32 | 'name': '',
33 | 'title': '',
34 | 'mobile': '',
35 | 'companyName': '',
36 | 'mobileVerify': false,
37 | 'more': '',
38 | 'avatarUrl': '',
39 | 'isDefault': false,
40 | 'email': '',
41 | 'address': '',
42 | 'loglat': '',
43 | 'language': ''
44 | }
45 | }
46 | },
47 | cardDataName: function (e) {
48 | this.setData({
49 | 'cardData.data.name': e.detail.value
50 | })
51 | },
52 | cardDataTitle: function (e) {
53 | this.setData({
54 | 'cardData.data.title': e.detail.value
55 | })
56 | },
57 | cardDataMobile: function (e) {
58 | this.setData({
59 | 'cardData.data.mobile': e.detail.value
60 | })
61 | },
62 | cardDataCompanyName: function (e) {
63 | this.setData({
64 | 'cardData.data.companyName': e.detail.value
65 | })
66 | },
67 | cardDataMore: function (e) {
68 | this.setData({
69 | 'cardData.data.more': e.detail.value
70 | })
71 | },
72 | cardDataEmail: function (e) {
73 | this.setData({
74 | 'cardData.data.email': e.detail.value
75 | })
76 | },
77 | enCardDataName: function (e) {
78 | this.setData({
79 | 'enCardData.data.name': e.detail.value
80 | })
81 | },
82 | enCardDataTitle: function (e) {
83 | this.setData({
84 | 'enCardData.data.title': e.detail.value
85 | })
86 | },
87 | enCardDataMobile: function (e) {
88 | this.setData({
89 | 'enCardData.data.mobile': e.detail.value
90 | })
91 | },
92 | enCardDataCompanyName: function (e) {
93 | this.setData({
94 | 'enCardData.data.companyName': e.detail.value
95 | })
96 | },
97 | enCardDataMore: function (e) {
98 | this.setData({
99 | 'enCardData.data.more': e.detail.value
100 | })
101 | },
102 | enCardDataEmail: function (e) {
103 | this.setData({
104 | 'enCardData.data.email': e.detail.value
105 | })
106 | },
107 | onLoad: function (options) {
108 | // 页面初始化 options为页面跳转所带来的参数
109 | var that = this
110 | if (options.id === "0") {
111 | that.setData({
112 | iseng: true,
113 | 'cardData.data.id': '',
114 | 'cardData.data.mobile': wx.getStorageSync('loginSuccessData').mobile,
115 | 'cardData.data.mobileVerify': wx.getStorageSync('loginSuccessData').mobVerify,
116 | 'cardData.data.avatarUrl': wx.getStorageSync('userInfo').avatarUrl,
117 | 'cardData.data.name': wx.getStorageSync('userInfo').nickName,
118 |
119 | })
120 | wx.setNavigationBarTitle({
121 | title: '创建名片'
122 | })
123 | } else {
124 | that.setData({
125 | iseng: false,
126 | 'cardData.data.id': options.id,
127 | 'cardData.data.mobile': wx.getStorageSync('loginSuccessData').mobile,
128 | 'cardData.data.mobileVerify': wx.getStorageSync('loginSuccessData').mobVerify,
129 | 'cardData.data.avatarUrl': wx.getStorageSync('userInfo').avatarUrl,
130 | 'cardData.data.name': wx.getStorageSync('userInfo').nickName,
131 |
132 | })
133 | wx.setNavigationBarTitle({
134 | title: '编辑名片'
135 | })
136 |
137 | var editDataCard = {
138 | 'url': 'Card/GetCard',
139 | 'data': {
140 | 'id': options.id
141 | }
142 | }
143 | app.postData(editDataCard, function (res) {
144 | if (res.data.language === 1) {
145 | that.setData({
146 | ischinese: false,
147 | isen: true,
148 | 'enCardData.data': res.data
149 | })
150 | return
151 | } else if (res.data.language === 0) {
152 | that.setData({
153 | 'cardData.data': res.data,
154 | })
155 | return
156 | }
157 | })
158 | }
159 | },
160 | toVerifyCode: function () {
161 | wx.navigateTo({
162 | url: '../phoneverify/phoneverify'
163 | })
164 | },
165 | onReady: function () {
166 | // 页面渲染完成
167 | },
168 | onShow: function () {
169 | // 页面显示
170 | },
171 | onHide: function () {
172 | // 页面隐藏
173 | },
174 | onUnload: function () {
175 | // 页面关闭
176 | },
177 | tabEng: function () {
178 | var that = this
179 |
180 | if (that.data.isen) {
181 | wx.setStorageSync('enCardData', that.data.enCardData)
182 | if (wx.getStorageSync('cardData')) {
183 | return that.setData({
184 | ischinese: true,
185 | isen: false,
186 | cardData: wx.getStorageSync('cardData')
187 | })
188 | } else {
189 | return that.setData({
190 | ischinese: true,
191 | isen: false,
192 | cardData: that.data.cardData
193 | })
194 | }
195 | }
196 | if (that.data.ischinese) {
197 | wx.setStorageSync('cardData', that.data.cardData)
198 |
199 | if (wx.getStorageSync('enCardData')) {
200 | return that.setData({
201 | ischinese: false,
202 | isen: true,
203 | enCardData: wx.getStorageSync('enCardData')
204 | })
205 | } else {
206 | return that.setData({
207 | ischinese: false,
208 | isen: true,
209 | enCardData: that.data.enCardData
210 | })
211 | }
212 | }
213 | },
214 | openAddress: function () {
215 | var that = this
216 | wx.chooseLocation({
217 | success: function (res) {
218 | that.setData({
219 | 'cardData.data.address': res.address,
220 | 'cardData.data.loglat': res.latitude + ',' + res.longitude
221 | })
222 | that.setData({
223 | 'enCardData.data.address': res.address,
224 | 'enCardData.data.loglat': res.latitude + ',' + res.longitude
225 | })
226 | },
227 | fail: function (res) {
228 | // fail
229 | },
230 | complete: function (res) {
231 | // complete
232 | }
233 | })
234 | },
235 | formSubmit: function (e) {
236 | var that = this
237 | if (e.detail.value.name === '' || e.detail.value.mobile === '') {
238 | if (e.detail.value.name === '') {
239 | wx.showToast({
240 | title: '姓名必填',
241 | image: '../../images/error.png',
242 | duration: 2000
243 | })
244 | }
245 | if (e.detail.value.mobile === '') {
246 | wx.showToast({
247 | title: '手机必填',
248 | image: '../../images/error.png',
249 | duration: 2000
250 | })
251 | }
252 | } else {
253 |
254 | var data = {
255 | 'url': 'Card/SaveCard',
256 | 'data': {
257 | 'id': that.data.cardData.data.id,
258 | 'name': e.detail.value.name,
259 | 'title': e.detail.value.title,
260 | 'mobile': e.detail.value.mobile,
261 | 'companyName': e.detail.value.companyName,
262 | 'more': e.detail.value.more,
263 | // 'avatarUrl': that.data.cardData.data.avatarUrl,
264 | // 'isDefaurl': false,
265 | 'email': e.detail.value.email,
266 | 'address': e.detail.value.address,
267 | 'loglat': that.data.cardData.data.loglat,
268 | 'language': 0
269 | }
270 | }
271 | if (e.detail.value.email != '') {
272 | var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
273 | if (!filter.test(e.detail.value.email)) {
274 | wx.showToast({
275 | title: '邮箱错误',
276 | image: '../../images/error.png',
277 | duration: 2000
278 | })
279 | } else {
280 |
281 | app.postData(data, function (res) {
282 | if (res.code === 200) {
283 | var loginSuccessData = {
284 | 'token': wx.getStorageSync('loginSuccessData').token,
285 | 'mobile': e.detail.value.mobile,
286 | 'mobVerify': wx.getStorageSync('loginSuccessData').mobVerify
287 | }
288 | wx.setStorageSync('loginSuccessData', loginSuccessData)
289 | wx.navigateBack({
290 | delta: 1
291 | })
292 | }
293 | })
294 | }
295 |
296 | } else {
297 | app.postData(data, function (res) {
298 | if (res.code === 200) {
299 | var loginSuccessData = {
300 | 'token': wx.getStorageSync('loginSuccessData').token,
301 | 'mobile': e.detail.value.mobile,
302 | 'mobVerify': wx.getStorageSync('loginSuccessData').mobVerify
303 | }
304 | wx.setStorageSync('loginSuccessData', loginSuccessData)
305 | wx.navigateBack({
306 | delta: 1
307 | })
308 | }
309 | })
310 | }
311 | }
312 | },
313 | enformSubmit: function (e) {
314 | var that = this
315 | if (e.detail.value.name === '' || e.detail.value.mobile === '') {
316 | if (e.detail.value.name === '') {
317 | wx.showToast({
318 | title: 'name required',
319 | image: '../../images/error.png',
320 | duration: 2000
321 | })
322 | }
323 | if (e.detail.value.mobile === '') {
324 | wx.showToast({
325 | title: 'mobile required',
326 | image: '../../images/error.png',
327 | duration: 2000
328 | })
329 | }
330 | } else {
331 | var data = {
332 | 'url': 'Card/SaveCard',
333 | 'data': {
334 | 'id': that.data.cardData.data.id,
335 | 'name': e.detail.value.name,
336 | 'title': e.detail.value.title,
337 | 'mobile': e.detail.value.mobile,
338 | 'companyName': e.detail.value.companyName,
339 | 'more': e.detail.value.more,
340 | // 'avatarUrl': that.data.cardData.data.avatarUrl,
341 | // 'isDefaurl': false,
342 | 'email': e.detail.value.email,
343 | 'address': e.detail.value.address,
344 | 'loglat': that.data.enCardData.data.loglat,
345 | 'language': 1
346 | }
347 | }
348 | if (e.detail.value.email != '') {
349 | var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
350 | if (!filter.test(e.detail.value.email)) {
351 | wx.showToast({
352 | title: 'Email Error',
353 | image: '../../images/error.png',
354 | duration: 2000
355 | })
356 | } else {
357 | app.postData(data, function (res) {
358 | if (res.code === 200) {
359 | var loginSuccessData = {
360 | 'token': wx.getStorageSync('loginSuccessData').token,
361 | 'mobile': e.detail.value.mobile,
362 | 'mobVerify': wx.getStorageSync('loginSuccessData').mobVerify
363 | }
364 | wx.setStorageSync('loginSuccessData', loginSuccessData)
365 | wx.navigateBack({
366 | delta: 1
367 | })
368 | }
369 | })
370 | }
371 | } else {
372 | app.postData(data, function (res) {
373 | if (res.code === 200) {
374 | var loginSuccessData = {
375 | 'token': wx.getStorageSync('loginSuccessData').token,
376 | 'mobile': e.detail.value.mobile,
377 | 'mobVerify': wx.getStorageSync('loginSuccessData').mobVerify
378 | }
379 | wx.setStorageSync('loginSuccessData', loginSuccessData)
380 | wx.navigateBack({
381 | delta: 1
382 | })
383 | }
384 | })
385 |
386 | }
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 | }
403 | },
404 | formReset: function () {
405 | console.log('form发生了reset事件')
406 | }
407 | })
--------------------------------------------------------------------------------
/pages/cardcase/cardcase.js:
--------------------------------------------------------------------------------
1 | // pages/cardcase/cardcase.js
2 | var app = getApp()
3 |
4 | Page({
5 | data: {
6 | lastX: 0,
7 | lastY: 0,
8 | text: "没有滑动",
9 | touchDotX: 0,
10 | touchDotY: 0,
11 | istouch: true,
12 | green: false,
13 | slideselecgroup: false,
14 | selectedgroup: [],
15 | selecgroup: [],
16 | setgroup: [],
17 | isselecgroup: true,
18 | ismovebtn: false,
19 | hidden: true,
20 | isaddgroupinput: true,
21 | nocancel: false,
22 | tip: '',
23 | buttonDisabled: false,
24 | modalHidden: true,
25 | show: false,
26 | isSearch: false,
27 | cardcasedata: {},
28 | currenttab: 0,
29 | isbindCompanyId: false,
30 | userCardData: {
31 | 'url': 'Card/GetCollectCard',
32 | 'data': {
33 | 'sortType': 1,
34 | 'key': ''
35 | }
36 | },
37 | cardgroup: {
38 | 'url': 'Card/GetGroups',
39 | 'data': []
40 | },
41 | setGroup: {
42 | 'url': 'Card/SetGroup',
43 | 'data': {
44 | 'gid': '',
45 | 'cid': []
46 | }
47 | }
48 | },
49 | //切换tab
50 | swiperTab: function (e) {
51 | var that = this;
52 | if (that.data.currenttab === e.target.dataset.current) {
53 | return false;
54 | } else {
55 | that.setData({
56 | currenttab: e.target.dataset.current
57 | })
58 | }
59 | },
60 | //显示tab的内容
61 | handleSwiperItem: function (e) {
62 | var that = this;
63 | that.setData({
64 | currenttab: that.data.currenttab
65 | })
66 | },
67 | //拨打电话
68 | phoneCall: function (e) {
69 | wx.makePhoneCall({
70 | phoneNumber: e.target.dataset.id //仅为示例,并非真实的电话号码
71 | })
72 | },
73 | //获取个人名片数据
74 | getUserCardData: function (that, sortType, key) {
75 | that.setData({
76 | ismovebtn: false,
77 | 'userCardData.data.sortType': sortType,
78 | 'userCardData.data.key': key
79 | })
80 | app.postData(that.data.userCardData, function (res) {
81 | that.setData({
82 | cardcasedata: res.data
83 | })
84 | if (sortType == 3) {
85 | if (wx.getStorageSync('loginSuccessData').bindCompanyId != '') {
86 | that.setData({
87 | isbindCompanyId: true
88 | })
89 | }
90 | that.data.cardcasedata.map(function (v, i) {
91 | v.checked = false
92 | v.items.map(function (v2, i2) {
93 | v2.checked = false
94 | v2.radio = false
95 | })
96 | })
97 |
98 | that.setData({
99 | cardcasedata: that.data.cardcasedata
100 | })
101 | }
102 | })
103 | },
104 | //显示搜索
105 | showSearch: function () {
106 | var that = this
107 | that.setData({
108 | isSearch: !that.data.isSearch
109 | })
110 | },
111 | //获取搜索数据
112 | getSearchData: function (e) {
113 | var that = this
114 | that.getUserCardData(that, that.data.userCardData.data.sortType, e.detail.value)
115 | },
116 | //切换排序类型
117 | selectSortType: function () {
118 | var that = this
119 | wx.showActionSheet({
120 | itemColor: '#757575',
121 | itemList: ['按时间排序', '按字母排序', '按公司排序', '按分组排序'],
122 | success: function (res) {
123 | if (typeof (res.tapIndex) != 'undefined') {
124 | that.setData({
125 | 'userCardData.data.sortType': res.tapIndex
126 | })
127 | that.getUserCardData(that, res.tapIndex, '')
128 | }
129 | },
130 | fail: function (res) {
131 | console.log(res.errMsg)
132 | }
133 | })
134 | },
135 | //显示选择分组
136 | showSelectGroup: function () {
137 | var that = this
138 | that.setData({
139 | isselecgroup: !that.data.isselecgroup
140 | })
141 | },
142 | //显示分组弹框
143 | showSelectGroupPop: function () {
144 | var that = this
145 | that.setData({
146 | hidden: !that.data.hidden
147 | })
148 |
149 | app.getData(that.data.cardgroup.url, function (res) {
150 | that.setData({
151 | 'cardgroup.data': res.data
152 | })
153 |
154 | that.data.cardcasedata.map(function (v, i) {
155 | v.items.map(function (v1, i1) {
156 | if (v1.checked || v1.radio) {
157 | that.data.setgroup.push(v1.id)
158 | that.setData({
159 | 'setGroup.data.cid': that.data.setgroup,
160 | 'cardgroup.data': that.data.cardgroup.data
161 | })
162 | }
163 | })
164 | })
165 | })
166 | },
167 | //分组弹框 取消按钮
168 | cancel: function (e) {
169 | var that = this
170 | that.setData({
171 | hidden: !that.data.hidden,
172 | setgroup: [],
173 | green: false,
174 | isselecgroup: true
175 | })
176 | that.getUserCardData(that, 3, '')
177 | },
178 | //分组弹框 确定按钮
179 | confirm: function (e) {
180 | var that = this
181 | if (that.data.setGroup.data.gid == '') {
182 | wx.showToast({
183 | title: '请选择组',
184 | icon: 'success',
185 | duration: 2000,
186 | complete: function () {
187 | }
188 | })
189 | } else {
190 | app.postData(that.data.setGroup, function (res) {
191 | wx.showToast({
192 | title: res.msg,
193 | icon: 'success',
194 | duration: 2000,
195 | complete: function () {
196 | that.setData({
197 | hidden: !that.data.hidden,
198 | setgroup: [],
199 | isselecgroup: true,
200 | green: false,
201 |
202 | })
203 | that.getUserCardData(that, 3, '')
204 | }
205 | })
206 | })
207 | }
208 | },
209 | //多选
210 | checkboxChange: function (e) {
211 | var that = this
212 | if (e.detail.value.length === 1) {
213 | that.data.cardcasedata[e.currentTarget.dataset.id].checked = true
214 | that.data.cardcasedata[e.currentTarget.dataset.id].items
215 | .map(function (v, i) {
216 | v.checked = true
217 | })
218 | that.setData({
219 | cardcasedata: that.data.cardcasedata,
220 | green: true
221 | })
222 | } else {
223 | that.data.cardcasedata[e.currentTarget.dataset.id].checked = false
224 | that.data.cardcasedata[e.currentTarget.dataset.id].items
225 | .map(function (v, i) {
226 | v.checked = false
227 | })
228 | that.setData({
229 | green: false,
230 | cardcasedata: that.data.cardcasedata
231 | })
232 | }
233 |
234 | that.data.cardcasedata.map(function (v, i) {
235 | v.items.map(function (v, i) {
236 | if (v.checked == true) {
237 | that.setData({
238 | green: true,
239 | })
240 | }
241 | })
242 | })
243 |
244 | },
245 | //单选
246 | checkboxChange2: function (e) {
247 | var that = this
248 | var a;
249 | var a1 = []
250 | var aitems = that.data.cardcasedata[e.currentTarget.dataset.index].items
251 | if (e.detail.value.length === 1) {
252 | that.data.cardcasedata.map(function (v, i) {
253 | v.items.map(function (v1, i1) {
254 | if (v1.id === e.currentTarget.dataset.id) {
255 | v1.checked = true
256 | }
257 | })
258 | })
259 | that.setData({
260 | green: true,
261 | cardcasedata: that.data.cardcasedata
262 | })
263 | } else {
264 | that.data.cardcasedata.map(function (v, i) {
265 | v.items.map(function (v1, i1) {
266 | if (v1.id === e.currentTarget.dataset.id) {
267 | v1.checked = false
268 | }
269 | })
270 | })
271 | that.setData({
272 | cardcasedata: that.data.cardcasedata
273 | })
274 | }
275 |
276 | that.data.cardcasedata.map(function (v, i) {
277 | v.items.map(function (v1, i1) {
278 | if (v1.checked || v1.radio) {
279 | a = v.items
280 | }
281 | })
282 | })
283 | aitems.map(function (v, i) {
284 | if (v.checked) {
285 | a1.push(v.checked)
286 | }
287 | })
288 |
289 | if (a1.length == aitems.length) {
290 | that.data.cardcasedata[e.currentTarget.dataset.index].checked = true
291 | that.setData({
292 | green: true,
293 | cardcasedata: that.data.cardcasedata
294 | })
295 | } else if (a1.length == 0 || a1.length < aitems.length) {
296 | that.data.cardcasedata[e.currentTarget.dataset.index].checked = false
297 | that.setData({
298 | cardcasedata: that.data.cardcasedata
299 | })
300 | }
301 |
302 | if (typeof (a) == 'undefined') {
303 | that.setData({
304 | green: false,
305 | cardcasedata: that.data.cardcasedata
306 | })
307 | }
308 | },
309 | //移动某个分组
310 | selectGroup: function (e) {
311 | var that = this
312 | that.data.cardgroup.data.map(function (v, i) {
313 | v.select = false
314 | if (v.id == e.currentTarget.dataset.id) {
315 | if (v.select) {
316 | v.select = false
317 | } else {
318 | v.select = true
319 | }
320 | }
321 | })
322 | that.setData({
323 | 'setGroup.data.gid': e.currentTarget.dataset.id,
324 | 'cardgroup.data': that.data.cardgroup.data
325 | })
326 | },
327 | //删除分组
328 | deleteGroup: function (e) {
329 | var that = this
330 | var data = {
331 | 'url': 'Card/DeleteGroup',
332 | 'data': {
333 | id: e.currentTarget.dataset.id
334 | }
335 | }
336 |
337 | wx.showModal({
338 | title: '提示',
339 | content: '是否确认删除 "' + e.currentTarget.dataset.name + '" ?',
340 | success: function (res) {
341 | if (res.confirm) {
342 | app.postData(data, function (res) {
343 | wx.showToast({
344 | title: '删除成功',
345 | icon: 'success',
346 | duration: 2000,
347 | complete: function () {
348 | app.getData(that.data.cardgroup.url, function (res2) {
349 | that.setData({
350 | 'cardgroup.data': res2.data,
351 | })
352 | })
353 | }
354 | })
355 | })
356 | } else if (res.cancel) {
357 | console.log('用户点击取消')
358 | }
359 | }
360 | })
361 | },
362 | //添加分组
363 | addGroup: function () {
364 | var that = this
365 | that.setData({
366 | isaddgroupinput: false
367 | })
368 | },
369 | //获取 新增分组名称
370 | getDddGroupName: function (e) {
371 | var that = this
372 | if (e.detail.value != '') {
373 | var data = {
374 | 'url': 'Card/SaveGroup',
375 | 'data': {
376 | 'id': '',
377 | 'name': e.detail.value
378 | }
379 | }
380 | app.postData(data, function (res) {
381 | app.getData(that.data.cardgroup.url, function (res2) {
382 | that.setData({
383 | 'cardgroup.data': res2.data,
384 | isaddgroupinput: true
385 | })
386 | })
387 | })
388 | } else {
389 | wx.showToast({
390 | title: '分组名不能为空',
391 | icon: 'success',
392 | duration: 2000,
393 | complete: function () {
394 | that.setData({
395 | isaddgroupinput: true
396 | })
397 | }
398 | })
399 | }
400 | },
401 | setDddGroupName: function (e) {
402 | var that = this
403 | that.setData({
404 | isaddgroupinput: true
405 | })
406 | },
407 | //滑动开始
408 | handleStart: function (e) {
409 | var that = this
410 | if (that.data.userCardData.data.sortType == 3 && that.data.isselecgroup) {
411 | if (e.currentTarget.dataset.name != '公司资源') {
412 | that.setData({
413 | touchDotX: e.touches[0].pageX,
414 | touchDotY: e.touches[0].pageY
415 | })
416 | }
417 | }
418 |
419 | },
420 | //滑动过程中
421 | handleMove: function (e) {
422 | var that = this
423 |
424 | if (that.data.userCardData.data.sortType == 3 && that.data.isselecgroup) {
425 | if (e.currentTarget.dataset.name != '公司资源') {
426 | var touchMoveX = e.touches[0].pageX,
427 | touchMoveY = e.touches[0].pageY,
428 |
429 |
430 | X = touchMoveX - that.data.touchDotX,
431 | Y = touchMoveY - that.data.touchDotY
432 |
433 | if (Math.abs(X) > Math.abs(Y) && X > 0) {
434 | // right alert('向右')
435 | that.data.cardcasedata.map(function (v, i) {
436 | v.items.map(function (v2, i2) {
437 | if (v2.id === e.currentTarget.dataset.id) {
438 | v2.radio = false
439 | }
440 | })
441 | })
442 | that.setData({
443 | ismovebtn: false,
444 | cardcasedata: that.data.cardcasedata
445 | })
446 | }
447 |
448 | if (Math.abs(X) > Math.abs(Y) && X < 0) {
449 | // right alert('向左')
450 | if (X < -50) {
451 | that.data.cardcasedata.map(function (v, i) {
452 | v.items.map(function (v2, i2) {
453 | v2.radio = false
454 | if (v2.id === e.currentTarget.dataset.id) {
455 | v2.radio = true
456 | }
457 | })
458 | })
459 | that.setData({
460 | ismovebtn: true,
461 | cardcasedata: that.data.cardcasedata
462 | })
463 | }
464 | }
465 | }
466 | }
467 | },
468 | handleSkip: function (e) {
469 | wx.navigateTo({
470 | url: '../carddetails/carddetails?id=' + e.currentTarget.dataset.id + '&type=1'
471 | })
472 | },
473 | //隐藏遮罩层
474 | hideMade: function () {
475 | var that = this
476 | that.data.cardcasedata.map(function (v, i) {
477 | v.items.map(function (v2, i2) {
478 | v2.radio = false
479 | })
480 | })
481 | that.setData({
482 | ismovebtn: false,
483 | cardcasedata: that.data.cardcasedata
484 | })
485 | },
486 | onLoad: function (e) {
487 | var that = this
488 | that.getUserCardData(that, 1, '')
489 | },
490 | onShow: function () {
491 | var that = this
492 | that.getUserCardData(that, that.data.userCardData.data.sortType, '')
493 | },
494 | canvasIdErrorCallback: function (e) {
495 | console.error(e.detail.errMsg)
496 | },
497 | })
--------------------------------------------------------------------------------
/js/qqmap-wx-jssdk.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 微信小程序JavaScriptSDK
3 | *
4 | * @version 1.0
5 | * @date 2017-01-10
6 | * @author jaysonzhou@tencent.com
7 | */
8 |
9 | var ERROR_CONF = {
10 | KEY_ERR: 311,
11 | KEY_ERR_MSG: 'key格式错误',
12 | PARAM_ERR: 310,
13 | PARAM_ERR_MSG: '请求参数信息有误',
14 | SYSTEM_ERR: 600,
15 | SYSTEM_ERR_MSG: '系统错误',
16 | WX_ERR_CODE: 1000,
17 | WX_OK_CODE: 200
18 | };
19 | var BASE_URL = 'https://apis.map.qq.com/ws/';
20 | var URL_SEARCH = BASE_URL + 'place/v1/search';
21 | var URL_SUGGESTION = BASE_URL + 'place/v1/suggestion';
22 | var URL_GET_GEOCODER = BASE_URL + 'geocoder/v1/';
23 | var URL_CITY_LIST = BASE_URL + 'district/v1/list';
24 | var URL_AREA_LIST = BASE_URL + 'district/v1/getchildren';
25 | var URL_DISTANCE = BASE_URL + 'distance/v1/';
26 | var Utils = {
27 | /**
28 | * 得到终点query字符串
29 | * @param {Array|String} 检索数据
30 | */
31 | location2query(data) {
32 | if (typeof data == 'string') {
33 | return data;
34 | }
35 | var query = '';
36 | for (var i = 0; i < data.length; i++) {
37 | var d = data[i];
38 | if (!!query) {
39 | query += ';';
40 | }
41 | if (d.location) {
42 | query = query + d.location.lat + ',' + d.location.lng;
43 | }
44 | if (d.latitude && d.longitude) {
45 | query = query + d.latitude + ',' + d.longitude;
46 | }
47 | }
48 | return query;
49 | },
50 |
51 | /**
52 | * 使用微信接口进行定位
53 | */
54 | getWXLocation(success, fail, complete) {
55 | wx.getLocation({
56 | type: 'gcj02',
57 | success: success,
58 | fail: fail,
59 | complete: complete
60 | });
61 | },
62 |
63 | /**
64 | * 获取location参数
65 | */
66 | getLocationParam(location) {
67 | if (typeof location == 'string') {
68 | var locationArr = location.split(',');
69 | if (locationArr.length === 2) {
70 | location = {
71 | latitude: location.split(',')[0],
72 | longitude: location.split(',')[1]
73 | };
74 | } else {
75 | location = {};
76 | }
77 | }
78 | return location;
79 | },
80 |
81 | /**
82 | * 回调函数默认处理
83 | */
84 | polyfillParam(param) {
85 | param.success = param.success || function () { };
86 | param.fail = param.fail || function () { };
87 | param.complete = param.complete || function () { };
88 | },
89 |
90 | /**
91 | * 验证param对应的key值是否为空
92 | *
93 | * @param {Object} param 接口参数
94 | * @param {String} key 对应参数的key
95 | */
96 | checkParamKeyEmpty(param, key) {
97 | if (!param[key]) {
98 | var errconf = this.buildErrorConfig(ERROR_CONF.PARAM_ERR, ERROR_CONF.PARAM_ERR_MSG + key +'参数格式有误');
99 | param.fail(errconf);
100 | param.complete(errconf);
101 | return true;
102 | }
103 | return false;
104 | },
105 |
106 | /**
107 | * 验证参数中是否存在检索词keyword
108 | *
109 | * @param {Object} param 接口参数
110 | */
111 | checkKeyword(param){
112 | return !this.checkParamKeyEmpty(param, 'keyword');
113 | },
114 |
115 | /**
116 | * 验证location值
117 | *
118 | * @param {Object} param 接口参数
119 | */
120 | checkLocation(param) {
121 | var location = this.getLocationParam(param.location);
122 | if (!location || !location.latitude || !location.longitude) {
123 | var errconf = this.buildErrorConfig(ERROR_CONF.PARAM_ERR, ERROR_CONF.PARAM_ERR_MSG + ' location参数格式有误')
124 | param.fail(errconf);
125 | param.complete(errconf);
126 | return false;
127 | }
128 | return true;
129 | },
130 |
131 | /**
132 | * 构造错误数据结构
133 | * @param {Number} errCode 错误码
134 | * @param {Number} errMsg 错误描述
135 | */
136 | buildErrorConfig(errCode, errMsg) {
137 | return {
138 | status: errCode,
139 | message: errMsg
140 | };
141 | },
142 |
143 | /**
144 | * 构造微信请求参数,公共属性处理
145 | *
146 | * @param {Object} param 接口参数
147 | * @param {Object} param 配置项
148 | */
149 | buildWxRequestConfig(param, options) {
150 | var that = this;
151 | options.header = { "content-type": "application/json" };
152 | options.method = 'GET';
153 | options.success = function (res) {
154 | var data = res.data;
155 | if (data.status === 0) {
156 | param.success(data);
157 | } else {
158 | param.fail(data);
159 | }
160 | };
161 | options.fail = function (res) {
162 | res.statusCode = ERROR_CONF.WX_ERR_CODE;
163 | param.fail(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, result.errMsg));
164 | };
165 | options.complete = function (res) {
166 | var statusCode = +res.statusCode;
167 | switch(statusCode) {
168 | case ERROR_CONF.WX_ERR_CODE: {
169 | param.complete(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg));
170 | break;
171 | }
172 | case ERROR_CONF.WX_OK_CODE: {
173 | var data = res.data;
174 | if (data.status === 0) {
175 | param.complete(data);
176 | } else {
177 | param.complete(that.buildErrorConfig(data.status, data.message));
178 | }
179 | break;
180 | }
181 | default:{
182 | param.complete(that.buildErrorConfig(ERROR_CONF.SYSTEM_ERR, ERROR_CONF.SYSTEM_ERR_MSG));
183 | }
184 |
185 | }
186 | }
187 | return options;
188 | },
189 |
190 | /**
191 | * 处理用户参数是否传入坐标进行不同的处理
192 | */
193 | locationProcess(param, locationsuccess, locationfail, locationcomplete) {
194 | var that = this;
195 | locationfail = locationfail || function (res) {
196 | res.statusCode = ERROR_CONF.WX_ERR_CODE;
197 | param.fail(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg));
198 | };
199 | locationcomplete = locationcomplete || function (res) {
200 | if (res.statusCode == ERROR_CONF.WX_ERR_CODE) {
201 | param.complete(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg));
202 | }
203 | };
204 | if (!param.location) {
205 | that.getWXLocation(locationsuccess, locationfail, locationcomplete);
206 | } else if (that.checkLocation(param)) {
207 | var location = Utils.getLocationParam(param.location);
208 | locationsuccess(location);
209 | }
210 | }
211 | }
212 |
213 |
214 | class QQMapWX {
215 |
216 | /**
217 | * 构造函数
218 | *
219 | * @param {Object} options 接口参数,key 为必选参数
220 | */
221 | constructor(options) {
222 | if (!options.key) {
223 | throw Error('key值不能为空');
224 | }
225 | this.key = options.key;
226 | }
227 |
228 | /**
229 | * POI周边检索
230 | *
231 | * @param {Object} options 接口参数对象
232 | *
233 | * 参数对象结构可以参考
234 | * @see http://lbs.qq.com/webservice_v1/guide-search.html
235 | */
236 | search(options) {
237 | var that = this;
238 | options = options || {};
239 |
240 | Utils.polyfillParam(options);
241 |
242 | if (!Utils.checkKeyword(options)) {
243 | return;
244 | }
245 |
246 | var requestParam = {
247 | keyword: options.keyword,
248 | orderby: options.orderby || '_distance',
249 | page_size: options.page_size || 10,
250 | page_index: options.page_index || 1,
251 | output: 'json',
252 | key: that.key
253 | };
254 |
255 | if (options.address_format) {
256 | requestParam.address_format = options.address_format;
257 | }
258 |
259 | if (options.filter) {
260 | requestParam.filter = options.filter;
261 | }
262 |
263 | var distance = options.distance || "1000";
264 | var auto_extend = options.auto_extend || 1;
265 |
266 | var locationsuccess = function (result) {
267 | requestParam.boundary = "nearby(" + result.latitude + "," + result.longitude + "," + distance + "," + auto_extend +")";
268 | wx.request(Utils.buildWxRequestConfig(options, {
269 | url: URL_SEARCH,
270 | data: requestParam
271 | }));
272 | }
273 | Utils.locationProcess(options, locationsuccess);
274 | }
275 |
276 | /**
277 | * sug模糊检索
278 | *
279 | * @param {Object} options 接口参数对象
280 | *
281 | * 参数对象结构可以参考
282 | * http://lbs.qq.com/webservice_v1/guide-suggestion.html
283 | */
284 | getSuggestion(options) {
285 | var that = this;
286 | options = options || {};
287 | Utils.polyfillParam(options);
288 |
289 | if (!Utils.checkKeyword(options)) {
290 | return;
291 | }
292 |
293 | var requestParam = {
294 | keyword: options.keyword,
295 | region: options.region || '全国',
296 | region_fix: options.region_fix || 0,
297 | policy: options.policy || 0,
298 | output: 'json',
299 | key: that.key
300 | };
301 | wx.request(Utils.buildWxRequestConfig(options, {
302 | url: URL_SUGGESTION,
303 | data: requestParam
304 | }));
305 | }
306 |
307 | /**
308 | * 逆地址解析
309 | *
310 | * @param {Object} options 接口参数对象
311 | *
312 | * 请求参数结构可以参考
313 | * http://lbs.qq.com/webservice_v1/guide-gcoder.html
314 | */
315 | reverseGeocoder(options) {
316 | var that = this;
317 | options = options || {};
318 | Utils.polyfillParam(options);
319 | var requestParam = {
320 | coord_type: options.coord_type || 5,
321 | get_poi: options.get_poi || 0,
322 | output: 'json',
323 | key: that.key
324 | };
325 | if (options.poi_options) {
326 | requestParam.poi_options = options.poi_options
327 | }
328 |
329 | var locationsuccess = function (result) {
330 | requestParam.location = result.latitude + ',' + result.longitude;
331 | wx.request(Utils.buildWxRequestConfig(options, {
332 | url: URL_GET_GEOCODER,
333 | data: requestParam
334 | }));
335 | };
336 | Utils.locationProcess(options, locationsuccess);
337 | }
338 |
339 | /**
340 | * 地址解析
341 | *
342 | * @param {Object} options 接口参数对象
343 | *
344 | * 请求参数结构可以参考
345 | * http://lbs.qq.com/webservice_v1/guide-geocoder.html
346 | */
347 | geocoder(options) {
348 | var that = this;
349 | options = options || {};
350 | Utils.polyfillParam(options);
351 |
352 | if (Utils.checkParamKeyEmpty(options, 'address')) {
353 | return;
354 | }
355 |
356 | var requestParam = {
357 | address: options.address,
358 | output: 'json',
359 | key: that.key
360 | };
361 |
362 | wx.request(Utils.buildWxRequestConfig(options, {
363 | url: URL_GET_GEOCODER,
364 | data: requestParam
365 | }));
366 | }
367 |
368 |
369 | /**
370 | * 获取城市列表
371 | *
372 | * @param {Object} options 接口参数对象
373 | *
374 | * 请求参数结构可以参考
375 | * http://lbs.qq.com/webservice_v1/guide-region.html
376 | */
377 | getCityList(options) {
378 | var that = this;
379 | options = options || {};
380 | Utils.polyfillParam(options);
381 | var requestParam = {
382 | output: 'json',
383 | key: that.key
384 | };
385 |
386 | wx.request(Utils.buildWxRequestConfig(options, {
387 | url: URL_CITY_LIST,
388 | data: requestParam
389 | }));
390 | }
391 |
392 | /**
393 | * 获取对应城市ID的区县列表
394 | *
395 | * @param {Object} options 接口参数对象
396 | *
397 | * 请求参数结构可以参考
398 | * http://lbs.qq.com/webservice_v1/guide-region.html
399 | */
400 | getDistrictByCityId(options) {
401 | var that = this;
402 | options = options || {};
403 | Utils.polyfillParam(options);
404 |
405 | if (Utils.checkParamKeyEmpty(options, 'id')) {
406 | return;
407 | }
408 |
409 | var requestParam = {
410 | id: options.id || '',
411 | output: 'json',
412 | key: that.key
413 | };
414 |
415 | wx.request(Utils.buildWxRequestConfig(options, {
416 | url: URL_AREA_LIST,
417 | data: requestParam
418 | }));
419 | }
420 |
421 | /**
422 | * 用于单起点到多终点的路线距离(非直线距离)计算:
423 | * 支持两种距离计算方式:步行和驾车。
424 | * 起点到终点最大限制直线距离10公里。
425 | *
426 | * @param {Object} options 接口参数对象
427 | *
428 | * 请求参数结构可以参考
429 | * http://lbs.qq.com/webservice_v1/guide-distance.html
430 | */
431 | calculateDistance(options) {
432 | var that = this;
433 | options = options || {};
434 | Utils.polyfillParam(options);
435 |
436 | if (Utils.checkParamKeyEmpty(options, 'to')) {
437 | return;
438 | }
439 |
440 | var requestParam = {
441 | mode: options.mode || 'walking',
442 | to: Utils.location2query(options.to),
443 | output: 'json',
444 | key: that.key
445 | };
446 |
447 | var locationsuccess = function (result) {
448 | requestParam.from = result.latitude + ',' + result.longitude;
449 | wx.request(Utils.buildWxRequestConfig(options, {
450 | url: URL_DISTANCE,
451 | data: requestParam
452 | }));
453 | }
454 | if (options.from) {
455 | options.location = options.from;
456 | }
457 |
458 | Utils.locationProcess(options, locationsuccess);
459 | }
460 | }
461 |
462 | module.exports = QQMapWX;
--------------------------------------------------------------------------------
/iconfont/demo_symbol.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
27 |
IconFont 图标
28 |
29 |
30 | -
31 |
34 |
搜索
35 | #icon-sousuo
36 |
37 |
38 | -
39 |
42 |
名片
43 | #icon-card
44 |
45 |
46 | -
47 |
50 |
时间
51 | #icon-shijian
52 |
53 |
54 | -
55 |
58 |
A
59 | #icon-letter-a-outline
60 |
61 |
62 | -
63 |
66 |
设置
67 | #icon-shezhi
68 |
69 |
70 | -
71 |
74 |
勾选
75 | #icon-gouxuan
76 |
77 |
78 | -
79 |
82 |
定位
83 | #icon-location
84 |
85 |
86 | -
87 |
90 |
打钩
91 | #icon-dagou
92 |
93 |
94 | -
95 |
98 |
下拉
99 | #icon-xiala
100 |
101 |
102 | -
103 |
106 |
访客预约
107 | #icon-fangkeyuyue
108 |
109 |
110 | -
111 |
114 |
登录_手机验证
115 | #icon-shoujiyanzheng
116 |
117 |
118 | -
119 |
122 |
我的
123 | #icon-user
124 |
125 |
126 | -
127 |
130 |
电话
131 | #icon-dianhua
132 |
133 |
134 | -
135 |
138 |
朋友圈
139 | #icon-icon1460188600932
140 |
141 |
142 | -
143 |
146 |
名片
147 | #icon-mingpian-copy
148 |
149 |
150 | -
151 |
154 |
默认
155 | #icon-moren
156 |
157 |
158 | -
159 |
162 |
邮箱
163 | #icon-youxiang
164 |
165 |
166 | -
167 |
170 |
部门
171 | #icon-bumen
172 |
173 |
174 | -
175 |
178 |
组
179 | #icon-zu
180 |
181 |
182 | -
183 |
186 |
足迹
187 | #icon-zuji
188 |
189 |
190 | -
191 |
194 |
验证
195 | #icon-yanzheng
196 |
197 |
198 | -
199 |
202 |
名片夹
203 | #icon-mingpianjia1
204 |
205 |
206 | -
207 |
210 |
搜索_搜索
211 | #icon-sousuo_sousuo
212 |
213 |
214 | -
215 |
218 |
关于
219 | #icon-guanyu
220 |
221 |
222 | -
223 |
226 |
右侧小程序二维码
227 | #icon-youcexiaochengxuerweima
228 |
229 |
230 | -
231 |
234 |
小程序
235 | #icon-xiaochengxu
236 |
237 |
238 | -
239 |
242 |
中英文切换-显示中英文
243 | #icon-zhongyingwenqiehuan-xianshizhongyingwen
244 |
245 |
246 | -
247 |
250 |
arrows_circle_minus
251 | #icon-arrows_circle_minus
252 |
253 |
254 | -
255 |
258 |
arrows_circle_plus
259 | #icon-arrows_circle_plus
260 |
261 |
262 | -
263 |
266 |
公司
267 | #icon-gongsi
268 |
269 |
270 | -
271 |
274 |
angle-right
275 | #icon-angle-right
276 |
277 |
278 | -
279 |
282 |
angle-left
283 | #icon-angle-left
284 |
285 |
286 | -
287 |
290 |
arrows_circle_remove
291 | #icon-arrows_circle_remove1
292 |
293 |
294 |
295 |
296 |
297 |
symbol引用
298 |
299 |
300 |
这是一种全新的使用方式,应该说这才是未来的主流,也是平台目前推荐的用法。相关介绍可以参考这篇文章
301 | 这种用法其实是做了一个svg的集合,与另外两种相比具有如下特点:
302 |
303 | - 支持多色图标了,不再受单色限制。
304 | - 通过一些技巧,支持像字体那样,通过
font-size,color来调整样式。
305 | - 兼容性较差,支持 ie9+,及现代浏览器。
306 | - 浏览器渲染svg的性能一般,还不如png。
307 |
308 |
使用步骤如下:
309 |
第一步:引入项目下面生成的symbol代码:
310 |
311 |
第二步:加入通用css代码(引入一次就行):
312 |
<style type="text/css">
313 | .icon {
314 | width: 1em; height: 1em;
315 | vertical-align: -0.15em;
316 | fill: currentColor;
317 | overflow: hidden;
318 | }
319 | </style>
320 |
第三步:挑选相应图标并获取类名,应用于页面:
321 |
<svg class="icon" aria-hidden="true">
322 | <use xlink:href="#icon-xxx"></use>
323 | </svg>
324 |
325 |
326 |
327 |
328 |
--------------------------------------------------------------------------------
/iconfont/iconfont.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |