Browse Source

fix: 问题修复

master
jiannibang 4 years ago
parent
commit
e0cf21a84c
  1. 13
      miniprogram/app.js
  2. 84
      miniprogram/js/cities.js
  3. 5
      miniprogram/pages/index/index.js

13
miniprogram/app.js

@ -7,13 +7,6 @@ App({
this.malls = new Malls();
this.coupons = new Coupons();
this.globalData = {};
if (!wx.cloud) {
console.error("请使用 2.2.3 或以上的基础库以使用云能力");
} else {
await wx.cloud.init({
traceUser: true,
});
}
},
async getOpenid() {
if (this.openid) return this.openid;
@ -71,10 +64,8 @@ App({
})
);
console.log(data);
const { result } = await wx.cloud.callFunction({
name: "login",
});
this.openid = result;
this.openid = data.openid;
return this.openid;
},
});

84
miniprogram/js/cities.js

@ -1,58 +1,50 @@
import {
axios
} from './libs'
let cities = []
import { axios } from "./libs";
let cities = [];
const cityIndexMap = { 广州市: "G", 南京市: "N" };
const init = async () => {
const db = wx.cloud.database()
const [{
data: {
value: cityIndexMap
}
}, malls] = await Promise.all([db.collection('config').doc('cityIndexMap').get(), axios.get('/Api/Coupon/MallList')])
cities = Object.values(malls.reduce((acc, nxt) => {
const [malls] = await Promise.all([axios.get("/Api/Coupon/MallList")]);
cities = Object.values(
malls.reduce((acc, nxt) => {
const mall = {
name: nxt.name,
code: nxt.mallCode
}
code: nxt.mallCode,
};
if (acc[nxt.areaName]) {
acc[nxt.areaName].malls.push(mall)
} else acc[nxt.areaName] = {
acc[nxt.areaName].malls.push(mall);
} else
acc[nxt.areaName] = {
name: nxt.areaName,
malls: [mall],
index: cityIndexMap[nxt.areaName]
}
return acc
}, {}))
cities.sort((a, b) => a.index.charCodeAt(0) - b.index.charCodeAt(0))
}
index: cityIndexMap[nxt.areaName],
};
return acc;
}, {})
);
cities.sort((a, b) => a.index.charCodeAt(0) - b.index.charCodeAt(0));
};
export const getCities = async () => {
if (!cities.length) {
await init()
return cities
} else return cities
}
await init();
return cities;
} else return cities;
};
const toRadians = lonlat => lonlat / 180 * Math.PI;
const ToDigits = radian => radian / Math.PI * 180;
const R = 6371
const r = 50
const offset = Math.asin(r / 2 / R) * 2
const toRadians = (lonlat) => (lonlat / 180) * Math.PI;
const ToDigits = (radian) => (radian / Math.PI) * 180;
const R = 6371;
const r = 50;
const offset = Math.asin(r / 2 / R) * 2;
const getRestrict = (lon, lat) => {
const lonR = toRadians(lon)
const latR = toRadians(lat)
return [lonR - offset, lonR + offset, latR - offset, latR + offset].map(ToDigits)
}
const lonR = toRadians(lon);
const latR = toRadians(lat);
return [lonR - offset, lonR + offset, latR - offset, latR + offset].map(
ToDigits
);
};
const getMall = ([minLon, maxLon, minLat, maxLat]) =>
new Promise(resolve => {
})
new Promise((resolve) => {});
export const getNearMall = async ({
longitude,
latitude
}) => {
const restrict = getRestrict(longitude, latitude)
return (await getCities())[0]
}
export const getNearMall = async ({ longitude, latitude }) => {
const restrict = getRestrict(longitude, latitude);
return (await getCities())[0];
};

5
miniprogram/pages/index/index.js

@ -32,10 +32,7 @@ Page({
couponCode,
});
}
const db = wx.cloud.database();
const {
data: { value: shareTitle },
} = await db.collection("config").doc("shareTitle").get();
const shareTitle = "";
this.setData({
shareTitle,
});

Loading…
Cancel
Save