|
@@ -7,6 +7,12 @@ Page({
|
|
|
*/
|
|
*/
|
|
|
data: {
|
|
data: {
|
|
|
loginStatus: false,
|
|
loginStatus: false,
|
|
|
|
|
+ regModalVisible: false,
|
|
|
|
|
+ bindShipVisible: false,
|
|
|
|
|
+ userInfo: {},
|
|
|
|
|
+ shipInfo: {},
|
|
|
|
|
+ shipName: "", // 新增:船舶名称
|
|
|
|
|
+ shipMmsi: "", // 新增:船舶MMSI
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
async login() {
|
|
async login() {
|
|
@@ -14,17 +20,25 @@ Page({
|
|
|
wx.showToast({
|
|
wx.showToast({
|
|
|
title: "正在初始化登录信息...",
|
|
title: "正在初始化登录信息...",
|
|
|
icon: "none",
|
|
icon: "none",
|
|
|
- duration: 1500,
|
|
|
|
|
|
|
+ duration: 500,
|
|
|
});
|
|
});
|
|
|
wxSetSessionKey();
|
|
wxSetSessionKey();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
wx.showLoading({
|
|
wx.showLoading({
|
|
|
title: "正在登录...",
|
|
title: "正在登录...",
|
|
|
|
|
+ mask: true,
|
|
|
});
|
|
});
|
|
|
let { data } = await postApi("/login/openid", {
|
|
let { data } = await postApi("/login/openid", {
|
|
|
openId: wx.getStorageSync("openId"),
|
|
openId: wx.getStorageSync("openId"),
|
|
|
});
|
|
});
|
|
|
|
|
+ await new Promise((resolve) => {
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ }, 500);
|
|
|
|
|
+ });
|
|
|
|
|
+ wx.hideLoading();
|
|
|
|
|
+
|
|
|
if (data.status == 0) {
|
|
if (data.status == 0) {
|
|
|
let obj = {
|
|
let obj = {
|
|
|
...data.result.userInfo,
|
|
...data.result.userInfo,
|
|
@@ -34,32 +48,121 @@ Page({
|
|
|
wx.setStorageSync(key, obj[key]);
|
|
wx.setStorageSync(key, obj[key]);
|
|
|
});
|
|
});
|
|
|
wx.setStorageSync("accessToken", data.result.tokenInfo.tokenValue);
|
|
wx.setStorageSync("accessToken", data.result.tokenInfo.tokenValue);
|
|
|
- } else {
|
|
|
|
|
- wx.showToast({
|
|
|
|
|
- title: data.msg,
|
|
|
|
|
- icon: "none",
|
|
|
|
|
- duration: 1500,
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- wx.hideLoading();
|
|
|
|
|
wx.switchTab({
|
|
wx.switchTab({
|
|
|
url: "/pages/takePhoto/takePhoto",
|
|
url: "/pages/takePhoto/takePhoto",
|
|
|
});
|
|
});
|
|
|
- }, 1000);
|
|
|
|
|
- },
|
|
|
|
|
- onLoad: function (options) {
|
|
|
|
|
- if (wx.getStorageSync("userId") && wx.getStorageSync("shipName")) {
|
|
|
|
|
- this.setData({
|
|
|
|
|
- loginStatus: true,
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ wx.setStorageSync("accessToken", data.result.tokenInfo.tokenValue);
|
|
|
|
|
+
|
|
|
|
|
+ if (data?.result?.userInfo?.userId) {
|
|
|
|
|
+ wx.showModal({
|
|
|
|
|
+ title: "提示",
|
|
|
|
|
+ content: "您已注册但尚未绑定船舶,去绑定?",
|
|
|
|
|
+ confirmText: "去绑定",
|
|
|
|
|
+ cancelText: "取消",
|
|
|
|
|
+ success: (res) => {
|
|
|
|
|
+ // 使用箭头函数修正this指向
|
|
|
|
|
+ if (res.confirm) {
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ bindShipVisible: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ regModalVisible: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
+ async init() {
|
|
|
|
|
+ let { data } = await postApi("/login/openid", {
|
|
|
|
|
+ openId: wx.getStorageSync("openId"),
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ hideRegModal() {
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ regModalVisible: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ async goToRegister(e) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (e.detail.errMsg == "getPhoneNumber:ok") {
|
|
|
|
|
+ wx.showLoading({
|
|
|
|
|
+ title: "正在登录...",
|
|
|
|
|
+ mask: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ let { data } = await postApi("/wx/getPhoneNumber", {
|
|
|
|
|
+ code: e.detail.code,
|
|
|
|
|
+ });
|
|
|
|
|
+ console.log("data1", data);
|
|
|
|
|
+ if (data.status === 0) {
|
|
|
|
|
+ let { phoneNumber: phone } = data.result;
|
|
|
|
|
+ // let phone = "19103808211";
|
|
|
|
|
+ wx.setStorageSync("phone", phone);
|
|
|
|
|
+ let { data } = await postApi("/login", {
|
|
|
|
|
+ phone,
|
|
|
|
|
+ openId: wx.getStorageSync("openId"),
|
|
|
|
|
+ });
|
|
|
|
|
+ console.log("data2", data);
|
|
|
|
|
+ await new Promise((resolve) => {
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ wx.hideLoading();
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ }, 1500);
|
|
|
|
|
+ });
|
|
|
|
|
+ if (data.status === 0) {
|
|
|
|
|
+ console.log(data, "data2");
|
|
|
|
|
+ wx.setStorageSync("accessToken", data.result.tokenInfo.tokenValue);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log(data, "data23");
|
|
|
|
|
+ if (data?.result?.userInfo?.userId) {
|
|
|
|
|
+ wx.showModal({
|
|
|
|
|
+ title: "提示",
|
|
|
|
|
+ content: "您已注册但尚未绑定船舶,去绑定?",
|
|
|
|
|
+ confirmText: "去绑定",
|
|
|
|
|
+ cancelText: "取消",
|
|
|
|
|
+ success: (res) => {
|
|
|
|
|
+ // 使用箭头函数修正this指向
|
|
|
|
|
+ if (res.confirm) {
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ bindShipVisible: true,
|
|
|
|
|
+ regModalVisible: false, // 关闭注册弹窗
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: data2.msg,
|
|
|
|
|
+ icon: "none",
|
|
|
|
|
+ duration: 5000,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ regModalVisible: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: "获取手机号失败",
|
|
|
|
|
+ duration: 5000,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: "请授权以登录",
|
|
|
|
|
+ icon: "error",
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {}
|
|
|
|
|
+ },
|
|
|
|
|
+ onLoad: function (options) {},
|
|
|
|
|
+
|
|
|
onShow() {
|
|
onShow() {
|
|
|
let v = wx.getAccountInfoSync();
|
|
let v = wx.getAccountInfoSync();
|
|
|
-
|
|
|
|
|
if (v.miniProgram.envVersion != "release") {
|
|
if (v.miniProgram.envVersion != "release") {
|
|
|
wx.showToast({
|
|
wx.showToast({
|
|
|
title: `当前环境:${
|
|
title: `当前环境:${
|
|
@@ -75,4 +178,57 @@ Page({
|
|
|
* 用户点击右上角分享
|
|
* 用户点击右上角分享
|
|
|
*/
|
|
*/
|
|
|
onShareAppMessage: function () {},
|
|
onShareAppMessage: function () {},
|
|
|
|
|
+
|
|
|
|
|
+ // 隐藏绑定船舶弹窗
|
|
|
|
|
+ async hideBindShipModal() {
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ bindShipVisible: false,
|
|
|
|
|
+ shipName: "", // 清空输入
|
|
|
|
|
+ shipMmsi: "", // 清空输入
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 确认绑定船舶
|
|
|
|
|
+ async confirmBindShip() {
|
|
|
|
|
+ const { shipName, shipMmsi } = this.data;
|
|
|
|
|
+ if (!shipName) {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: "请输入船舶名称",
|
|
|
|
|
+ icon: "none",
|
|
|
|
|
+ });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!shipMmsi) {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: "请输入船舶MMSI",
|
|
|
|
|
+ icon: "none",
|
|
|
|
|
+ });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ wx.showLoading({
|
|
|
|
|
+ title: "正在绑定...",
|
|
|
|
|
+ mask: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ let { data } = await postApi("/register", {
|
|
|
|
|
+ shipName,
|
|
|
|
|
+ shipMmsi,
|
|
|
|
|
+ });
|
|
|
|
|
+ if (data.status === 0) {
|
|
|
|
|
+ let obj = {
|
|
|
|
|
+ ...data.result.userInfo,
|
|
|
|
|
+ ...data.result.shipInfo,
|
|
|
|
|
+ };
|
|
|
|
|
+ Object.keys(obj).forEach(function (key) {
|
|
|
|
|
+ wx.setStorageSync(key, obj[key]);
|
|
|
|
|
+ });
|
|
|
|
|
+ wx.setStorageSync("accessToken", data.result.tokenInfo.tokenValue);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: data.msg,
|
|
|
|
|
+ icon: "none",
|
|
|
|
|
+ duration: 5000,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
});
|
|
});
|