util.js 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. import {
  11. TOKENNAME,
  12. HTTP_REQUEST_URL
  13. } from '../config/app.js';
  14. import store from '../store';
  15. import {
  16. customerType
  17. } from '@/api/api.js'
  18. // #ifdef APP-PLUS
  19. import permision from "./permission.js"
  20. // #endif
  21. export default {
  22. /**
  23. * opt object | string
  24. * to_url object | string
  25. * 例:
  26. * this.Tips('/pages/test/test'); 跳转不提示
  27. * this.Tips({title:'提示'},'/pages/test/test'); 提示并跳转
  28. * this.Tips({title:'提示'},{tab:1,url:'/pages/index/index'}); 提示并跳转值table上
  29. * tab=1 一定时间后跳转至 table上
  30. * tab=2 一定时间后跳转至非 table上
  31. * tab=3 一定时间后返回上页面
  32. * tab=4 关闭所有页面,打开到应用内的某个页面
  33. * tab=5 关闭当前页面,跳转到应用内的某个页面
  34. */
  35. Tips: function(opt, to_url) {
  36. if (typeof opt == 'string') {
  37. to_url = opt;
  38. opt = {};
  39. }
  40. let title = opt.title || '',
  41. icon = opt.icon || 'none',
  42. endtime = opt.endtime || 2000,
  43. success = opt.success;
  44. if (title) uni.showToast({
  45. title: title,
  46. icon: icon,
  47. duration: endtime,
  48. success
  49. })
  50. if (to_url != undefined) {
  51. if (typeof to_url == 'object') {
  52. let tab = to_url.tab || 1,
  53. url = to_url.url || '';
  54. switch (tab) {
  55. case 1:
  56. //一定时间后跳转至 table
  57. setTimeout(function() {
  58. uni.navigateTo({
  59. url: url
  60. })
  61. }, endtime);
  62. break;
  63. case 2:
  64. //跳转至非table页面
  65. setTimeout(function() {
  66. uni.navigateTo({
  67. url: url,
  68. })
  69. }, endtime);
  70. break;
  71. case 3:
  72. //返回上页面
  73. setTimeout(function() {
  74. // #ifndef H5
  75. uni.navigateBack({
  76. delta: parseInt(url),
  77. })
  78. // #endif
  79. // #ifdef H5
  80. history.back();
  81. // #endif
  82. }, endtime);
  83. break;
  84. case 4:
  85. //关闭所有页面,打开到应用内的某个页面
  86. setTimeout(function() {
  87. uni.reLaunch({
  88. url: url,
  89. })
  90. }, endtime);
  91. break;
  92. case 5:
  93. //关闭当前页面,跳转到应用内的某个页面
  94. setTimeout(function() {
  95. uni.redirectTo({
  96. url: url,
  97. })
  98. }, endtime);
  99. break;
  100. }
  101. } else if (typeof to_url == 'function') {
  102. setTimeout(function() {
  103. to_url && to_url();
  104. }, endtime);
  105. } else {
  106. //没有提示时跳转不延迟
  107. setTimeout(function() {
  108. uni.navigateTo({
  109. url: to_url,
  110. })
  111. }, title ? endtime : 0);
  112. }
  113. }
  114. },
  115. // 处理价格
  116. HandlePrice: function(num, type) {
  117. let obj = []
  118. if (typeof num == 'number') {
  119. obj = num.toString().split(".");
  120. } else {
  121. obj = num.split(".");
  122. }
  123. if (type) {
  124. if (obj.length) {
  125. return '.' + obj[1];
  126. } else {
  127. return ''
  128. }
  129. } else {
  130. return obj[0];
  131. }
  132. },
  133. // 将网络图片转化为base64
  134. getBase64Image: function(imageUrl) {
  135. return new Promise((resolve, reject) => {
  136. uni.request({
  137. url: imageUrl, // 服务器图片地址
  138. responseType: 'arraybuffer', // 设置响应类型为arraybuffer以接收二进制数据
  139. success: (res) => {
  140. let base64Image = 'data:image/jpeg;base64,' + uni.arrayBufferToBase64(res
  141. .data);
  142. resolve(base64Image);
  143. },
  144. fail: (err) => {
  145. reject(err);
  146. }
  147. });
  148. });
  149. },
  150. // 计算头部自定义导航高度;
  151. getWXStatusHeight() {
  152. // 获取距上
  153. const barTop = uni.getSystemInfoSync().statusBarHeight;
  154. // #ifdef MP
  155. // 获取胶囊按钮位置信息
  156. const menuButtonInfo = wx.getMenuButtonBoundingClientRect() || 0
  157. // 获取导航栏高度
  158. const barHeight = menuButtonInfo.height + (menuButtonInfo.top - barTop) * 2
  159. let barWidth = menuButtonInfo.width
  160. // #endif
  161. // #ifndef MP
  162. // 获取导航栏高度
  163. const barHeight = parseInt(barTop) + 10;
  164. let barWidth = '100%'
  165. // #endif
  166. return {
  167. barHeight,
  168. barTop,
  169. barWidth
  170. }
  171. },
  172. /**
  173. * 省市区地址分解
  174. */
  175. addressInfo: function(str) {
  176. let reg = /.+?(省|市|自治区|自治州|行政区|盟|旗|县|区)/g // 省市区的正则
  177. const area = str.match(reg) // 分割省市区
  178. let citys = ['北京市', '天津市', '上海市', '重庆市']
  179. let address_component = {
  180. city: "",
  181. district: "",
  182. province: area[0]
  183. }
  184. if (citys.indexOf(area[0]) == -1) {
  185. address_component.city = area[1]
  186. address_component.district = area[2]
  187. } else {
  188. address_component.city = area[0]
  189. address_component.district = area[1]
  190. }
  191. return address_component
  192. },
  193. /**
  194. * 跳转路径封装函数
  195. * @param url 跳转路径
  196. * 选择跳转到其他小程序时,在h5也可以跳转路径
  197. */
  198. JumpPath: function(url) {
  199. let arr = url.split('@APPID=');
  200. if (arr.length > 1) {
  201. //#ifdef MP
  202. uni.navigateToMiniProgram({
  203. appId: arr[arr.length - 1], // 此为生活缴费appid
  204. path: arr[0], // 此为生活缴费首页路径
  205. envVersion: "release",
  206. success: res => {
  207. console.log("打开成功", res);
  208. },
  209. fail: err => {
  210. console.log('sgdhgf', err);
  211. }
  212. })
  213. //#endif
  214. //#ifndef MP
  215. this.Tips({
  216. title: 'h5与app端不支持跳转外部小程序'
  217. });
  218. //#endif
  219. } else {
  220. if (url == '/pages/short_video/appSwiper/index' || url == '/pages/short_video/nvueSwiper/index') {
  221. //#ifdef APP
  222. url = '/pages/short_video/appSwiper/index'
  223. //#endif
  224. //#ifndef APP
  225. url = '/pages/short_video/nvueSwiper/index'
  226. //#endif
  227. }
  228. if (url.indexOf("http") != -1) {
  229. // #ifdef H5
  230. location.href = url;
  231. // #endif
  232. // #ifdef MP || APP-PLUS
  233. uni.navigateTo({
  234. url: `/pages/annex/web_view/index?url=${url}`
  235. });
  236. // #endif
  237. } else {
  238. if (['/pages/goods_cate/goods_cate', '/pages/order_addcart/order_addcart', '/pages/user/index',
  239. '/pages/index/index'
  240. ]
  241. .indexOf(url) == -1) {
  242. uni.navigateTo({
  243. url: url
  244. })
  245. } else {
  246. uni.reLaunch({
  247. url: url
  248. })
  249. }
  250. }
  251. }
  252. },
  253. /**
  254. * 移除数组中的某个数组并组成新的数组返回
  255. * @param array array 需要移除的数组
  256. * @param int index 需要移除的数组的键值
  257. * @param string | int 值
  258. * @return array
  259. *
  260. */
  261. ArrayRemove: function(array, index, value) {
  262. const valueArray = [];
  263. if (array instanceof Array) {
  264. for (let i = 0; i < array.length; i++) {
  265. if (typeof index == 'number' && array[index] != i) {
  266. valueArray.push(array[i]);
  267. } else if (typeof index == 'string' && array[i][index] != value) {
  268. valueArray.push(array[i]);
  269. }
  270. }
  271. }
  272. return valueArray;
  273. },
  274. /**
  275. * 生成海报获取文字
  276. * @param string text 为传入的文本
  277. * @param int num 为单行显示的字节长度
  278. * @return array
  279. */
  280. textByteLength: function(text, num) {
  281. let strLength = 0;
  282. let rows = 1;
  283. let str = 0;
  284. let arr = [];
  285. for (let j = 0; j < text.length; j++) {
  286. if (text.charCodeAt(j) > 255) {
  287. strLength += 2;
  288. if (strLength > rows * num) {
  289. strLength++;
  290. arr.push(text.slice(str, j));
  291. str = j;
  292. rows++;
  293. }
  294. } else {
  295. strLength++;
  296. if (strLength > rows * num) {
  297. arr.push(text.slice(str, j));
  298. str = j;
  299. rows++;
  300. }
  301. }
  302. }
  303. arr.push(text.slice(str, text.length));
  304. return [strLength, arr, rows] // [处理文字的总字节长度,每行显示内容的数组,行数]
  305. },
  306. /**
  307. * 获取分享海报
  308. * @param array arr2 海报素材
  309. * @param string store_name 素材文字
  310. * @param string price 价格
  311. * @param string ot_price 原始价格
  312. * @param function successFn 回调函数
  313. *
  314. *
  315. */
  316. PosterCanvas: function(fontColor, themeColor, siteName, arr2, store_name, price, ot_price, posterTitle, successFn) {
  317. let that = this;
  318. // uni.showLoading({
  319. // title: '海报生成中',
  320. // mask: true
  321. // });
  322. const ctx = uni.createCanvasContext('myCanvas');
  323. ctx.clearRect(0, 0, 0, 0);
  324. /**
  325. * 只能获取合法域名下的图片信息,本地调试无法获取
  326. *
  327. */
  328. ctx.fillStyle = '#fff';
  329. ctx.fillRect(0, 0, 750, 1306);
  330. uni.getImageInfo({
  331. src: arr2[0],
  332. success: function(res) {
  333. const WIDTH = res.width;
  334. // const HEIGHT = res.height;
  335. // ctx.drawImage(arr2[0], 0, 0, WIDTH, 1050);
  336. ctx.save();
  337. ctx.setFillStyle(themeColor);
  338. ctx.fillRect(0, 0, WIDTH, 108);
  339. ctx.setFontSize(33)
  340. ctx.setFillStyle('#fff');
  341. ctx.setTextAlign('center');
  342. ctx.fillText(posterTitle, WIDTH / 2, 65);
  343. ctx.save();
  344. ctx.drawImage(arr2[1], 32, 141, 685, 685);
  345. ctx.save();
  346. // ctx.setFillStyle(themeColor);
  347. // ctx.fillRect(32, 847, 85, 40);
  348. // ctx.setFontSize(30)
  349. // ctx.setFillStyle('#fff');
  350. // ctx.setTextAlign('left');
  351. // ctx.fillText('商城', 43, 878);
  352. // ctx.save();
  353. // ctx.setFontSize(36)
  354. // ctx.setFillStyle('#000');
  355. // ctx.fillText(siteName, 140, 880);
  356. // ctx.save();
  357. // const CONTENT_ROW_LENGTH = 36;
  358. const CONTENT_ROW_LENGTH = 35;
  359. let [contentLeng, contentArray, contentRows] = that.textByteLength(store_name,
  360. CONTENT_ROW_LENGTH);
  361. if (contentRows > 2) {
  362. contentRows = 2;
  363. let textArray = contentArray.slice(0, 2);
  364. textArray[textArray.length - 1] += '...';
  365. contentArray = textArray;
  366. }
  367. ctx.setTextAlign('left');
  368. ctx.setFontSize(38);
  369. ctx.setFillStyle('#000');
  370. let contentHh = 38;
  371. for (let m = 0; m < contentArray.length; m++) {
  372. if (m) {
  373. ctx.fillText(contentArray[m], 30, 900 + contentHh * m + 18);
  374. } else {
  375. ctx.fillText(contentArray[m], 30, 900 + contentHh * m);
  376. }
  377. }
  378. ctx.save();
  379. ctx.setTextAlign('left')
  380. ctx.setFontSize(32);
  381. ctx.setFillStyle('#999');
  382. ctx.fillText('¥' + ot_price, 30, 1148 + contentHh);
  383. var underline = function(ctx, text, x, y, size, color, thickness, offset) {
  384. var width = ctx.measureText(text).width;
  385. switch (ctx.textAlign) {
  386. case "center":
  387. x -= (width / 2);
  388. break;
  389. case "right":
  390. x -= width;
  391. break;
  392. }
  393. y += size + offset;
  394. ctx.beginPath();
  395. ctx.strokeStyle = color;
  396. ctx.lineWidth = thickness;
  397. ctx.moveTo(x, y);
  398. ctx.lineTo(x + width, y);
  399. ctx.stroke();
  400. }
  401. underline(ctx, '¥' + ot_price, 30, 1146, 28, '#999', 2, 0);
  402. ctx.save();
  403. ctx.setTextAlign('left')
  404. ctx.setFontSize(54);
  405. ctx.setFillStyle(fontColor);
  406. ctx.fillText('¥' + price, 20, 1070 + contentHh);
  407. ctx.save();
  408. ctx.setFillStyle('#F5F5F5');
  409. ctx.fillRect(0, 1222, WIDTH, 84);
  410. ctx.setFontSize(28);
  411. ctx.setFillStyle('#999');
  412. ctx.setTextAlign('center');
  413. ctx.fillText('长按识别图中的二维码查看商品详情', WIDTH / 2, 1272);
  414. ctx.save();
  415. let r = 93;
  416. let d = r * 2;
  417. let cx = WIDTH - d - 30;
  418. // let cy = 1112;
  419. let cy = 1000;
  420. ctx.arc(cx + r, cy + r, r, 0, 2 * Math.PI);
  421. ctx.drawImage(arr2[2], cx, cy, d, d);
  422. ctx.restore();
  423. // ctx.setTextAlign('left')
  424. // ctx.setFontSize(28);
  425. // ctx.setFillStyle('#999');
  426. // ctx.fillText('长按或扫描查看', 490, 1030 + contentHh);
  427. ctx.draw(true, function() {
  428. uni.canvasToTempFilePath({
  429. canvasId: 'myCanvas',
  430. fileType: 'png',
  431. // destWidth: WIDTH,
  432. // destHeight: HEIGHT,
  433. success: function(res) {
  434. // uni.hideLoading();
  435. successFn && successFn(res.tempFilePath);
  436. }
  437. })
  438. });
  439. },
  440. fail: function(err) {
  441. // uni.hideLoading();
  442. that.Tips({
  443. title: '无法获取图片信息'
  444. });
  445. }
  446. })
  447. },
  448. /**
  449. * 获取砍价/拼团海报
  450. * @param array arr2 海报素材 背景图
  451. * @param string store_name 素材文字
  452. * @param string price 价格
  453. * @param string ot_price 原始价格
  454. * @param function successFn 回调函数
  455. *
  456. *
  457. */
  458. bargainPosterCanvas: function(arr2, title, label, msg, price, wd, hg, successFn) {
  459. let that = this;
  460. const ctx = uni.createCanvasContext('myCanvas');
  461. ctx.clearRect(0, 0, 0, 0);
  462. /**
  463. * 只能获取合法域名下的图片信息,本地调试无法获取
  464. *
  465. */
  466. ctx.fillStyle = '#fff';
  467. ctx.fillRect(0, 0, wd * 2, hg * 2);
  468. uni.getImageInfo({
  469. src: arr2[0],
  470. success: function(res) {
  471. const WIDTH = res.width;
  472. const HEIGHT = res.height;
  473. ctx.drawImage(arr2[0], 0, 0, wd, hg);
  474. // 保证在不同机型对应坐标准确
  475. let labelx = 0.6500 //标签x
  476. let labely = 0.166 //标签y
  477. let pricex = 0.1857 //价格x
  478. let pricey = 0.180 //价格x
  479. let codex = 0.385 //二维码
  480. let codey = 0.77
  481. let picturex = 0.1571 //商品图左上点
  482. let picturey = 0.2916
  483. let picturebx = 0.6857 //商品图右下点
  484. let pictureby = 0.3916
  485. let msgx = 0.1036 //msg
  486. let msgy = 0.2306
  487. let codew = 0.25
  488. ctx.drawImage(arr2[1], wd * picturex, hg * picturey, wd * picturebx, hg * pictureby);
  489. ctx.drawImage(arr2[2], wd * codex, hg * codey, wd * codew, wd * codew);
  490. ctx.save();
  491. //标题
  492. const CONTENT_ROW_LENGTH = 28;
  493. let [contentLeng, contentArray, contentRows] = that.textByteLength(title,
  494. CONTENT_ROW_LENGTH);
  495. if (contentRows > 2) {
  496. contentRows = 2;
  497. let textArray = contentArray.slice(0, 2);
  498. textArray[textArray.length - 1] += '…';
  499. contentArray = textArray;
  500. }
  501. ctx.setTextAlign('left');
  502. ctx.setFillStyle('#000');
  503. if (contentArray.length < 2) {
  504. ctx.setFontSize(20);
  505. } else {
  506. ctx.setFontSize(20);
  507. }
  508. let contentHh = 8;
  509. for (let m = 0; m < contentArray.length; m++) {
  510. if (m) {
  511. ctx.fillText(contentArray[m], wd * msgx, 35 + contentHh * m + 18, 1100);
  512. } else {
  513. ctx.fillText(contentArray[m], wd * msgx, 35, 1100);
  514. }
  515. }
  516. // 标签内容
  517. ctx.setTextAlign('left')
  518. ctx.setFontSize(16);
  519. ctx.setFillStyle('#FFF');
  520. ctx.fillText(label, wd * labelx, hg * labely);
  521. ctx.save();
  522. // 价格
  523. ctx.setFillStyle('red');
  524. ctx.setFontSize(26);
  525. ctx.fillText(price, wd * pricex, hg * pricey);
  526. ctx.save();
  527. // msg
  528. ctx.setFillStyle('#333');
  529. ctx.setFontSize(16);
  530. ctx.fillText(msg, wd * msgx, hg * msgy);
  531. ctx.save();
  532. ctx.draw(true, () => {
  533. uni.canvasToTempFilePath({
  534. canvasId: 'myCanvas',
  535. fileType: 'png',
  536. quality: 1,
  537. success: (res) => {
  538. successFn && successFn(res.tempFilePath);
  539. uni.hideLoading();
  540. }
  541. })
  542. });
  543. },
  544. fail: function(err) {
  545. uni.hideLoading();
  546. that.Tips({
  547. title: '无法获取图片信息'
  548. });
  549. }
  550. })
  551. },
  552. /**
  553. * 图片圆角设置
  554. * @param string x x轴位置
  555. * @param string y y轴位置
  556. * @param string w 图片宽
  557. * @param string y 图片高
  558. * @param string r 圆角值
  559. */
  560. handleBorderRect(ctx, x, y, w, h, r) {
  561. ctx.beginPath();
  562. // 左上角
  563. ctx.arc(x + r, y + r, r, Math.PI, 1.5 * Math.PI);
  564. ctx.moveTo(x + r, y);
  565. ctx.lineTo(x + w - r, y);
  566. ctx.lineTo(x + w, y + r);
  567. // 右上角
  568. ctx.arc(x + w - r, y + r, r, 1.5 * Math.PI, 2 * Math.PI);
  569. ctx.lineTo(x + w, y + h - r);
  570. ctx.lineTo(x + w - r, y + h);
  571. // 右下角
  572. ctx.arc(x + w - r, y + h - r, r, 0, 0.5 * Math.PI);
  573. ctx.lineTo(x + r, y + h);
  574. ctx.lineTo(x, y + h - r);
  575. // 左下角
  576. ctx.arc(x + r, y + h - r, r, 0.5 * Math.PI, Math.PI);
  577. ctx.lineTo(x, y + r);
  578. ctx.lineTo(x + r, y);
  579. ctx.fill();
  580. ctx.closePath();
  581. },
  582. /**
  583. * 用户信息分享海报
  584. * @param array arr2 海报素材 1背景 0二维码
  585. * @param string nickname 昵称
  586. * @param string sitename 价格
  587. * @param function successFn 回调函数
  588. *
  589. *
  590. */
  591. userPosterCanvas: function(arr2, nickname, sitename, index, w, h, successFn) {
  592. let that = this;
  593. // uni.showLoading({
  594. // title: '海报生成中',
  595. // mask: true
  596. // });
  597. const ctx = uni.createCanvasContext('myCanvas' + index);
  598. ctx.clearRect(0, 0, 0, 0);
  599. /**
  600. * 只能获取合法域名下的图片信息,本地调试无法获取
  601. *
  602. */
  603. uni.getImageInfo({
  604. src: arr2[1],
  605. success: function(res) {
  606. // const WIDTH = res.width;
  607. // const HEIGHT = res.height;
  608. ctx.fillStyle = '#fff';
  609. console.log(0, 0, w, h,'0, 0, w, h')
  610. ctx.fillRect(0, 0, w, h);
  611. ctx.drawImage(arr2[1], 0, 0, w, h);
  612. ctx.save();
  613. ctx.setFontSize(16);
  614. ctx.setFillStyle('#333');
  615. // #ifdef APP
  616. ctx.fillText(nickname, w/18*3, h*0.82);
  617. // #endif
  618. // #ifndef APP
  619. ctx.fillText(nickname, w/18*3, h*0.82);
  620. // #endif
  621. // #ifdef APP
  622. ctx.drawImage(arr2[0], w/2-50, h/2-50, 100, 100);
  623. // #endif
  624. // #ifndef APP
  625. ctx.drawImage(arr2[0], w/2-50, h/2-50, 100, 100);
  626. // #endif
  627. ctx.save();
  628. ctx.save();
  629. const CONTENT_ROW_LENGTH = 25;
  630. const store_name = '邀请您加入' + sitename;
  631. let [contentLeng, contentArray, contentRows] = that.textByteLength(store_name,
  632. CONTENT_ROW_LENGTH);
  633. if (contentRows > 2) {
  634. contentRows = 2;
  635. let textArray = contentArray.slice(0, 2);
  636. textArray[textArray.length - 1] += '...';
  637. contentArray = textArray;
  638. }
  639. ctx.setTextAlign('left');
  640. ctx.setFillStyle('#999999');
  641. ctx.setFontSize(12);
  642. let contentHh = 38;
  643. for (let m = 0; m < contentArray.length; m++) {
  644. if (m) {
  645. ctx.fillText(contentArray[m], w/18*3, h*0.85);
  646. } else {
  647. ctx.fillText(contentArray[m], w/18*3, h*0.85);
  648. }
  649. }
  650. ctx.save();
  651. // #ifdef APP
  652. that.handleBorderRect(ctx, w/18*1, h*0.80, 24, 24, 12)
  653. // #endif
  654. // #ifndef APP
  655. that.handleBorderRect(ctx, w/18*1, h*0.80, 24, 24, 12)
  656. // #endif
  657. ctx.clip();
  658. // #ifdef APP
  659. ctx.drawImage(arr2[2],w/18*1, h*0.80, 24, 24);
  660. // #endif
  661. // #ifndef APP
  662. ctx.drawImage(arr2[2], w/18*1, h*0.80, 24, 24);
  663. // #endif
  664. ctx.draw(true, function() {
  665. uni.canvasToTempFilePath({
  666. canvasId: 'myCanvas' + index,
  667. fileType: 'png',
  668. quality: 1,
  669. success: function(res) {
  670. uni.hideLoading();
  671. successFn && successFn(res.tempFilePath);
  672. }
  673. })
  674. });
  675. },
  676. fail: function(err) {
  677. uni.hideLoading();
  678. that.Tips({
  679. title: ''
  680. });
  681. }
  682. })
  683. },
  684. // uniapp 判断 IOS和Android的GPS是否开启
  685. checkOpenGPSServiceByAndroidIOS() {
  686. let system = uni.getSystemInfoSync(); // 获取系统信息
  687. console.log('yyy', system);
  688. if (system.platform === 'android') { // 判断平台
  689. var context = plus.android.importClass("android.content.Context");
  690. var locationManager = plus.android.importClass("android.location.LocationManager");
  691. var main = plus.android.runtimeMainActivity();
  692. var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
  693. if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
  694. return false
  695. } else {
  696. return true
  697. }
  698. } else if (system.platform === 'ios' || 'devtools') {
  699. var cllocationManger = plus.ios.import("CLLocationManager");
  700. var enable = cllocationManger.locationServicesEnabled();
  701. var status = cllocationManger.authorizationStatus();
  702. plus.ios.deleteObject(cllocationManger);
  703. if (enable && status != 2) {
  704. return true
  705. console.log("手机系统的定位已经打开");
  706. } else {
  707. return false
  708. console.log("手机系统的定位没有打开");
  709. }
  710. }
  711. },
  712. /*
  713. * 单图上传
  714. * @param object opt
  715. * @param callable successCallback 成功执行方法 data
  716. * @param callable errorCallback 失败执行方法
  717. */
  718. uploadImageOne: function(opt, successCallback, errorCallback) {
  719. let that = this;
  720. // #ifdef APP
  721. let boolad = uni.getStorageSync("boolLoad") || false
  722. // if (permision.isIOS) {
  723. if (boolad) {
  724. upimg()
  725. } else {
  726. let title = '申请相册权限';
  727. let content = "是否允许访问相册用于上传图片?"
  728. uni.showModal({
  729. title,
  730. content,
  731. cancelText: '拒绝',
  732. confirmText: '允许',
  733. success: res => {
  734. if (res.confirm) {
  735. uni.setStorageSync("boolLoad", true)
  736. upimg()
  737. }
  738. },
  739. });
  740. }
  741. // #endif
  742. // #ifndef APP
  743. upimg()
  744. // #endif
  745. function upimg() {
  746. if (typeof opt === 'string') {
  747. let url = opt;
  748. opt = {};
  749. opt.url = url;
  750. }
  751. let count = opt.count || 1,
  752. sizeType = opt.sizeType || ['compressed'],
  753. sourceType = opt.sourceType || ['album', 'camera'],
  754. is_load = opt.is_load || true,
  755. uploadUrl = opt.url || '',
  756. inputName = opt.name || 'pics',
  757. fileType = opt.fileType || 'image';
  758. uni.chooseImage({
  759. count: count, //最多可以选择的图片总数
  760. sizeType: sizeType, // 可以指定是原图还是压缩图,默认二者都有
  761. sourceType: sourceType, // 可以指定来源是相册还是相机,默认二者都有
  762. success: function(res) {
  763. //启动上传等待中...
  764. uni.showLoading({
  765. title: '图片上传中',
  766. });
  767. uni.uploadFile({
  768. url: HTTP_REQUEST_URL + '/api/' + uploadUrl,
  769. filePath: res.tempFilePaths[0],
  770. fileType: fileType,
  771. name: inputName,
  772. formData: {
  773. 'filename': inputName
  774. },
  775. header: {
  776. // #ifdef MP
  777. "Content-Type": "multipart/form-data",
  778. // #endif
  779. [TOKENNAME]: 'Bearer ' + store.state.app.token
  780. },
  781. success: function(res) {
  782. uni.hideLoading();
  783. if (res.statusCode == 403) {
  784. that.Tips({
  785. title: res.data
  786. });
  787. } else if (res.statusCode == 413) {
  788. that.Tips({
  789. title: '上传图片失败,请重新上传小尺寸图片'
  790. });
  791. } else {
  792. let data = res.data ? JSON.parse(res.data) : {};
  793. if (data.status == 200) {
  794. successCallback && successCallback(data)
  795. } else {
  796. errorCallback && errorCallback(data);
  797. that.Tips({
  798. title: data.msg
  799. });
  800. }
  801. }
  802. },
  803. fail: function(res) {
  804. uni.hideLoading();
  805. that.Tips({
  806. title: '上传图片失败'
  807. });
  808. }
  809. })
  810. }
  811. })
  812. }
  813. },
  814. /*
  815. * 单图上传压缩版
  816. * @param object opt
  817. * @param callable successCallback 成功执行方法 data
  818. * @param callable errorCallback 失败执行方法
  819. */
  820. uploadImageChange: function(opt, successCallback, errorCallback, sizeCallback) {
  821. let that = this;
  822. // #ifdef APP
  823. let boolad = uni.getStorageSync("boolLoad") || false
  824. // if (permision.isIOS) {
  825. if (boolad || plus.os.name == "iOS") {
  826. upimg()
  827. } else {
  828. let title = '申请相册及相机权限';
  829. let content = "是否允许访问相册和相机用于拍摄上传图片?"
  830. uni.showModal({
  831. title,
  832. content,
  833. cancelText: '拒绝',
  834. confirmText: '允许',
  835. success: res => {
  836. if (res.confirm) {
  837. uni.setStorageSync("boolLoad", true)
  838. upimg()
  839. }
  840. },
  841. });
  842. }
  843. // #endif
  844. // #ifndef APP
  845. upimg()
  846. // #endif
  847. function upimg() {
  848. if (typeof opt === 'string') {
  849. let url = opt;
  850. opt = {};
  851. opt.url = url;
  852. }
  853. let count = opt.count || 1,
  854. sizeType = opt.sizeType || ['compressed'],
  855. sourceType = opt.sourceType || ['album', 'camera'],
  856. is_load = opt.is_load || true,
  857. uploadUrl = opt.url || '',
  858. inputName = opt.name || 'pics',
  859. fileType = opt.fileType || 'image';
  860. uni.chooseImage({
  861. count: count, //最多可以选择的图片总数
  862. sizeType: sizeType, // 可以指定是原图还是压缩图,默认二者都有
  863. sourceType: sourceType, // 可以指定来源是相册还是相机,默认二者都有
  864. success: function(res) {
  865. //启动上传等待中...
  866. let imgSrc
  867. let objImg = res.tempFilePaths;
  868. objImg.forEach(item => {
  869. uni.getImageInfo({
  870. src: item,
  871. success(ress) {
  872. uni.showLoading({
  873. title: '图片上传中',
  874. });
  875. if (res.tempFiles[0].size <= 2097152) {
  876. uploadImg(ress.path)
  877. return
  878. }
  879. // uploadImg(canvasPath.tempFilePath)
  880. let canvasWidth, canvasHeight, xs, maxWidth = 750
  881. xs = ress.width / ress.height // 宽高比例
  882. if (ress.width > maxWidth) {
  883. canvasWidth = maxWidth // 这里是最大限制宽度
  884. canvasHeight = maxWidth / xs
  885. } else {
  886. canvasWidth = ress.width
  887. canvasHeight = ress.height
  888. }
  889. sizeCallback && sizeCallback({
  890. w: canvasWidth,
  891. h: canvasHeight
  892. })
  893. let canvas = uni.createCanvasContext('canvas');
  894. canvas.width = canvasWidth
  895. canvas.height = canvasHeight
  896. canvas.clearRect(0, 0, canvasWidth, canvasHeight);
  897. canvas.drawImage(ress.path, 0, 0, canvasWidth,
  898. canvasHeight)
  899. canvas.save();
  900. // 这里的画布drawImage是一种异步属性 可能存在未绘制全就执行了draw的问题 so添加延迟
  901. setTimeout(e => {
  902. canvas.draw(true, () => {
  903. uni.canvasToTempFilePath({
  904. canvasId: 'canvas',
  905. fileType: 'JPEG',
  906. destWidth: canvasWidth,
  907. destHeight: canvasHeight,
  908. quality: 0.7,
  909. success: function(
  910. canvasPath
  911. ) {
  912. uploadImg(
  913. canvasPath
  914. .tempFilePath
  915. )
  916. }
  917. })
  918. });
  919. }, 200)
  920. }
  921. })
  922. })
  923. }
  924. })
  925. }
  926. function uploadImg(filePath) {
  927. uni.uploadFile({
  928. url: HTTP_REQUEST_URL + '/api/' + uploadUrl,
  929. filePath,
  930. fileType: fileType,
  931. name: inputName,
  932. formData: {
  933. 'filename': inputName
  934. },
  935. header: {
  936. // #ifdef MP
  937. "Content-Type": "multipart/form-data",
  938. // #endif
  939. [TOKENNAME]: 'Bearer ' + store.state.app.token
  940. },
  941. success: function(res) {
  942. uni.hideLoading();
  943. if (res.statusCode == 403) {
  944. that.Tips({
  945. title: res.data
  946. });
  947. } else {
  948. let data = res.data ? JSON.parse(res.data) : {};
  949. if (data.status == 200) {
  950. successCallback && successCallback(data)
  951. } else {
  952. errorCallback && errorCallback(data);
  953. that.Tips({
  954. title: data.msg
  955. });
  956. }
  957. }
  958. },
  959. fail: function(res) {
  960. uni.hideLoading();
  961. that.Tips({
  962. title: '上传图片失败'
  963. });
  964. }
  965. })
  966. }
  967. },
  968. /**
  969. * 处理客服不同的跳转;
  970. *
  971. */
  972. getCustomer(userInfo, url, storeInfo, show) {
  973. let self = this;
  974. customerType().then(res => {
  975. let data = res.data;
  976. if (data.customer_type == 1) {
  977. uni.makePhoneCall({
  978. phoneNumber: data.customer_phone
  979. });
  980. } else if (data.customer_type == 2) {
  981. let href = data.customer_url;
  982. let hrefO = href + '?uid=' + userInfo.uid + '&nickName=' + userInfo.nickname + '&phone=' +
  983. userInfo.phone + '&sex=' + userInfo.sex + '&avatar=' + userInfo.avatar +
  984. '&openid=' + userInfo.openid;
  985. let hrefT = href + '&uid=' + userInfo.uid + '&nickName=' + userInfo.nickname + '&phone=' +
  986. userInfo.phone + '&sex=' + userInfo.sex + '&avatar=' + userInfo.avatar +
  987. '&openid=' + userInfo.openid;
  988. let urls = encodeURIComponent(href.indexOf('?') === -1 ? hrefO : hrefT);
  989. if (data.customer_url.indexOf('work.weixin.qq.com') > 0) {
  990. // #ifdef MP
  991. wx.openCustomerServiceChat({
  992. extInfo: {
  993. url: data.customer_url
  994. },
  995. corpId: data.wechat_work_corpid,
  996. showMessageCard: show ? true : false,
  997. sendMessageTitle: show ? storeInfo.store_name : '',
  998. sendMessagePath: show ? storeInfo.path : '',
  999. sendMessageImg: show ? storeInfo.image : '',
  1000. success(res) {},
  1001. fail(err) {
  1002. self.Tips({
  1003. title: err.errMsg
  1004. });
  1005. }
  1006. })
  1007. // #endif
  1008. // #ifdef H5
  1009. return window.location.href = data.customer_url
  1010. // #endif
  1011. // #ifdef APP-PLUS
  1012. plus.runtime.openURL(data.customer_url)
  1013. // #endif
  1014. } else {
  1015. uni.navigateTo({
  1016. url: `/pages/annex/web_view/index?url=${urls}`
  1017. });
  1018. }
  1019. } else {
  1020. uni.navigateTo({
  1021. url: url || '/pages/extension/customer_list/chat'
  1022. })
  1023. }
  1024. }).catch(err => {
  1025. self.Tips({
  1026. title: err
  1027. });
  1028. })
  1029. },
  1030. /**
  1031. * 小程序头像获取上传
  1032. * @param uploadUrl 上传接口地址
  1033. * @param filePath 上传文件路径
  1034. * @param successCallback success回调
  1035. * @param errorCallback err回调
  1036. */
  1037. uploadImgs(uploadUrl, filePath, successCallback, errorCallback) {
  1038. let that = this;
  1039. uni.uploadFile({
  1040. url: HTTP_REQUEST_URL + '/api/' + uploadUrl,
  1041. filePath: filePath,
  1042. fileType: 'image',
  1043. name: 'pics',
  1044. formData: {
  1045. 'filename': 'pics'
  1046. },
  1047. header: {
  1048. // #ifdef MP
  1049. "Content-Type": "multipart/form-data",
  1050. // #endif
  1051. [TOKENNAME]: 'Bearer ' + store.state.app.token
  1052. },
  1053. success: (res) => {
  1054. uni.hideLoading();
  1055. if (res.statusCode == 403) {
  1056. that.Tips({
  1057. title: res.data
  1058. });
  1059. } else if (res.statusCode == 413) {
  1060. that.Tips({
  1061. title: '上传图片失败,请重新上传小尺寸图片'
  1062. });
  1063. } else {
  1064. let data = res.data ? JSON.parse(res.data) : {};
  1065. if (data.status == 200) {
  1066. successCallback && successCallback(data)
  1067. } else {
  1068. errorCallback && errorCallback(data);
  1069. that.Tips({
  1070. title: data.msg
  1071. });
  1072. }
  1073. }
  1074. },
  1075. fail: (err) => {
  1076. uni.hideLoading();
  1077. that.Tips({
  1078. title: '上传图片失败'
  1079. });
  1080. }
  1081. })
  1082. },
  1083. /**
  1084. * 小程序比较版本信息
  1085. * @param v1 当前版本
  1086. * @param v2 进行比较的版本
  1087. * @return boolen
  1088. *
  1089. */
  1090. compareVersion(v1, v2) {
  1091. v1 = v1.split('.')
  1092. v2 = v2.split('.')
  1093. const len = Math.max(v1.length, v2.length)
  1094. while (v1.length < len) {
  1095. v1.push('0')
  1096. }
  1097. while (v2.length < len) {
  1098. v2.push('0')
  1099. }
  1100. for (let i = 0; i < len; i++) {
  1101. const num1 = parseInt(v1[i])
  1102. const num2 = parseInt(v2[i])
  1103. if (num1 > num2) {
  1104. return 1
  1105. } else if (num1 < num2) {
  1106. return -1
  1107. }
  1108. }
  1109. return 0
  1110. },
  1111. /**
  1112. * 处理服务器扫码带进来的参数
  1113. * @param string param 扫码携带参数
  1114. * @param string k 整体分割符 默认为:&
  1115. * @param string p 单个分隔符 默认为:=
  1116. * @return object
  1117. *
  1118. */
  1119. // #ifdef MP
  1120. getUrlParams: function(param, k, p) {
  1121. if (typeof param != 'string') return {};
  1122. k = k ? k : '&'; //整体参数分隔符
  1123. p = p ? p : '='; //单个参数分隔符
  1124. var value = {};
  1125. if (param.indexOf(k) !== -1) {
  1126. param = param.split(k);
  1127. for (var val in param) {
  1128. if (param[val].indexOf(p) !== -1) {
  1129. var item = param[val].split(p);
  1130. value[item[0]] = item[1];
  1131. }
  1132. }
  1133. } else if (param.indexOf(p) !== -1) {
  1134. var item = param.split(p);
  1135. value[item[0]] = item[1];
  1136. } else {
  1137. return param;
  1138. }
  1139. return value;
  1140. },
  1141. // #endif
  1142. /*
  1143. * 合并数组
  1144. */
  1145. SplitArray(list, sp) {
  1146. if (typeof list != 'object') return [];
  1147. if (sp === undefined) sp = [];
  1148. for (var i = 0; i < list.length; i++) {
  1149. sp.push(list[i]);
  1150. }
  1151. return sp;
  1152. },
  1153. trim(backUrlCRshlcICwGdGY) {
  1154. return String.prototype.trim.call(backUrlCRshlcICwGdGY);
  1155. },
  1156. $h: {
  1157. //除法函数,用来得到精确的除法结果
  1158. //说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。
  1159. //调用:$h.Div(arg1,arg2)
  1160. //返回值:arg1除以arg2的精确结果
  1161. Div: function(arg1, arg2) {
  1162. arg1 = parseFloat(arg1);
  1163. arg2 = parseFloat(arg2);
  1164. var t1 = 0,
  1165. t2 = 0,
  1166. r1, r2;
  1167. try {
  1168. t1 = arg1.toString().split(".")[1].length;
  1169. } catch (e) {}
  1170. try {
  1171. t2 = arg2.toString().split(".")[1].length;
  1172. } catch (e) {}
  1173. r1 = Number(arg1.toString().replace(".", ""));
  1174. r2 = Number(arg2.toString().replace(".", ""));
  1175. return this.Mul(r1 / r2, Math.pow(10, t2 - t1));
  1176. },
  1177. //加法函数,用来得到精确的加法结果
  1178. //说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
  1179. //调用:$h.Add(arg1,arg2)
  1180. //返回值:arg1加上arg2的精确结果
  1181. Add: function(arg1, arg2) {
  1182. arg2 = parseFloat(arg2);
  1183. var r1, r2, m;
  1184. try {
  1185. r1 = arg1.toString().split(".")[1].length
  1186. } catch (e) {
  1187. r1 = 0
  1188. }
  1189. try {
  1190. r2 = arg2.toString().split(".")[1].length
  1191. } catch (e) {
  1192. r2 = 0
  1193. }
  1194. m = Math.pow(100, Math.max(r1, r2));
  1195. return (this.Mul(arg1, m) + this.Mul(arg2, m)) / m;
  1196. },
  1197. //减法函数,用来得到精确的减法结果
  1198. //说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的减法结果。
  1199. //调用:$h.Sub(arg1,arg2)
  1200. //返回值:arg1减去arg2的精确结果
  1201. Sub: function(arg1, arg2) {
  1202. arg1 = parseFloat(arg1);
  1203. arg2 = parseFloat(arg2);
  1204. var r1, r2, m, n;
  1205. try {
  1206. r1 = arg1.toString().split(".")[1].length
  1207. } catch (e) {
  1208. r1 = 0
  1209. }
  1210. try {
  1211. r2 = arg2.toString().split(".")[1].length
  1212. } catch (e) {
  1213. r2 = 0
  1214. }
  1215. m = Math.pow(10, Math.max(r1, r2));
  1216. //动态控制精度长度
  1217. n = (r1 >= r2) ? r1 : r2;
  1218. return ((this.Mul(arg1, m) - this.Mul(arg2, m)) / m).toFixed(n);
  1219. },
  1220. //乘法函数,用来得到精确的乘法结果
  1221. //说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
  1222. //调用:$h.Mul(arg1,arg2)
  1223. //返回值:arg1乘以arg2的精确结果
  1224. Mul: function(arg1, arg2) {
  1225. arg1 = parseFloat(arg1);
  1226. arg2 = parseFloat(arg2);
  1227. var m = 0,
  1228. s1 = arg1.toString(),
  1229. s2 = arg2.toString();
  1230. try {
  1231. m += s1.split(".")[1].length
  1232. } catch (e) {}
  1233. try {
  1234. m += s2.split(".")[1].length
  1235. } catch (e) {}
  1236. return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
  1237. },
  1238. },
  1239. // 获取地理位置;
  1240. $L: {
  1241. async getLocation() {
  1242. // #ifdef APP-PLUS
  1243. let status = await this.checkPermission();
  1244. if (status !== 1) {
  1245. return;
  1246. }
  1247. // #endif
  1248. // #ifdef MP-WEIXIN || MP-TOUTIAO || MP-QQ
  1249. let status = await this.getSetting();
  1250. if (status === 2) {
  1251. this.openSetting();
  1252. return;
  1253. }
  1254. // #endif
  1255. this.doGetLocation();
  1256. },
  1257. doGetLocation() {
  1258. uni.getLocation({
  1259. success: (res) => {
  1260. uni.removeStorageSync('CACHE_LONGITUDE');
  1261. uni.removeStorageSync('CACHE_LATITUDE');
  1262. uni.setStorageSync('CACHE_LONGITUDE', res.longitude);
  1263. uni.setStorageSync('CACHE_LATITUDE', res.latitude);
  1264. },
  1265. fail: (err) => {
  1266. // #ifdef MP-BAIDU
  1267. if (err.errCode === 202 || err.errCode === 10003) { // 202模拟器 10003真机 user deny
  1268. this.openSetting();
  1269. }
  1270. // #endif
  1271. // #ifndef MP-BAIDU
  1272. if (err.errMsg.indexOf("auth deny") >= 0) {
  1273. uni.showToast({
  1274. title: "访问位置被拒绝"
  1275. })
  1276. } else {
  1277. uni.showToast({
  1278. title: err.errMsg
  1279. })
  1280. }
  1281. // #endif
  1282. }
  1283. })
  1284. },
  1285. getSetting: function() {
  1286. return new Promise((resolve, reject) => {
  1287. uni.getSetting({
  1288. success: (res) => {
  1289. if (res.authSetting['scope.userLocation'] === undefined) {
  1290. resolve(0);
  1291. return;
  1292. }
  1293. if (res.authSetting['scope.userLocation']) {
  1294. resolve(1);
  1295. } else {
  1296. resolve(2);
  1297. }
  1298. }
  1299. });
  1300. });
  1301. },
  1302. openSetting: function() {
  1303. uni.openSetting({
  1304. success: (res) => {
  1305. if (res.authSetting && res.authSetting['scope.userLocation']) {
  1306. this.doGetLocation();
  1307. }
  1308. },
  1309. fail: (err) => {}
  1310. })
  1311. },
  1312. async checkPermission() {
  1313. let status = permision.isIOS ? await permision.requestIOS('location') :
  1314. await permision.requestAndroid('android.permission.ACCESS_FINE_LOCATION');
  1315. if (status === null || status === 1) {
  1316. status = 1;
  1317. } else if (status === 2) {
  1318. uni.showModal({
  1319. content: "系统定位已关闭",
  1320. confirmText: "确定",
  1321. showCancel: false,
  1322. success: function(res) {}
  1323. })
  1324. } else if (status.code) {
  1325. uni.showModal({
  1326. content: status.message
  1327. })
  1328. } else {
  1329. uni.showModal({
  1330. content: "需要定位权限",
  1331. confirmText: "设置",
  1332. success: function(res) {
  1333. if (res.confirm) {
  1334. permision.gotoAppSetting();
  1335. }
  1336. }
  1337. })
  1338. }
  1339. return status;
  1340. },
  1341. }
  1342. }