You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
1.9 KiB
92 lines
1.9 KiB
import { getMapData } from "./getMapData";
|
|
export const post = (url, data) =>
|
|
new Promise((resolve, reject) => {
|
|
wx.request({
|
|
url: "https://huiju.mapais.com/wxyj" + url,
|
|
method: "POST",
|
|
data,
|
|
success({ data, statusCode }) {
|
|
if (statusCode !== 200) return reject();
|
|
resolve(data);
|
|
},
|
|
});
|
|
});
|
|
const floors = [
|
|
{
|
|
name: "L1",
|
|
floorOrder: 0,
|
|
url: true,
|
|
floorId: "F1",
|
|
isPark: false,
|
|
},
|
|
{
|
|
name: "L2",
|
|
floorOrder: 1,
|
|
url: true,
|
|
floorId: "F2",
|
|
isPark: false,
|
|
},
|
|
{
|
|
name: "L3",
|
|
floorOrder: 2,
|
|
url: true,
|
|
floorId: "F3",
|
|
isPark: false,
|
|
},
|
|
{
|
|
name: "L4",
|
|
floorOrder: 3,
|
|
url: true,
|
|
floorId: "F4",
|
|
isPark: false,
|
|
},
|
|
{
|
|
name: "L5",
|
|
floorOrder: 4,
|
|
url: true,
|
|
floorId: "F5",
|
|
isPark: false,
|
|
},
|
|
];
|
|
App({
|
|
async onLaunch() {
|
|
// 展示本地存储能力
|
|
getMapData();
|
|
try {
|
|
this.globalData.openid = wx.getStorageSync("openid");
|
|
} catch (e) {
|
|
console.log(e);
|
|
}
|
|
if (this.globalData.openid)
|
|
return this.openidCbs.forEach((cb) => cb(this.globalData.openid));
|
|
|
|
try {
|
|
const { code } = await new Promise((resolve, reject) => {
|
|
wx.login({
|
|
success: resolve,
|
|
fail: reject,
|
|
});
|
|
});
|
|
const { data } = await post("/api/wxmp/session", {
|
|
code,
|
|
});
|
|
this.globalData.openid = data ? data.openid : null;
|
|
wx.setStorageSync("openid", this.globalData.openid);
|
|
this.openidCbs.forEach((cb) => cb(this.globalData.openid));
|
|
} catch (error) {
|
|
console.warn(error);
|
|
this.openidCbs.forEach((cb) => cb(null));
|
|
}
|
|
},
|
|
onOpenid(cb) {
|
|
this.openidCbs.push(cb);
|
|
},
|
|
openidCbs: [],
|
|
globalData: {
|
|
floors,
|
|
floorIdFloorOrderMap: floors.reduce(
|
|
(acc, nxt) => ({ ...acc, [nxt.floorId]: nxt.floorOrder }),
|
|
{}
|
|
),
|
|
},
|
|
});
|
|
|