1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- export function downloadFile({url}) {
- return new Promise((resolve, reject) => {
- wx.downloadFile({
- url,
- success: resolve,
- fail: reject
- });
- })
- }
- export function getQueryString(url, name) {
- let reg = new RegExp('(^|/?|&)' + name + '=([^&]*)(&|$)', 'i');
- let r = url.substr(1).match(reg);
- if (r != null) {
- return unescape(r[2]);
- }
- return null;
- }
- export function randomString(e) {
- for (var t = "", i = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", n = 0; n < e; n++)
- t += i.charAt(Math.floor(Math.random() * i.length));
- return t
- }
- export function isPhoneX () {
- return new Promise((resolve) => {
- wx.getSystemInfo({
- success: res=>{
- let modelmes = res.model;
- if (modelmes.search('iPhone X') != -1) {
- resolve(true)
- }
- resolve(false)
- }
- })
- })
- }
- export function getLocation () {
- return new Promise ( (resolve, reject) => {
- wx.getLocation({
- type: 'wgs84',
- success: function (res) {
- var latitude = res.latitude;
- var longitude = res.longitude;
- getApp().globalData.qqmapsdk.reverseGeocoder({
- location: {
- latitude: latitude,
- longitude: longitude
- },
- success: function (res) {
- var ad_info = res.result.ad_info;
- let city = ad_info.city.replace('市', '');
- resolve(city)
- },
- fail:function (res) {
- wx.showModal({
- title: '定位失败',
- });
- }
- });
- },
- fail(err) {
- wx.showModal({
- title: '定位失败,请手动选择城市',
- });
- }
- })
- })
- }
|