backend-moke 模拟弱网环境;一些小修改
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
const sleepTime = 0; // 模拟弱网环境等待时间
|
||||||
|
|
||||||
// 1. 导入http模块
|
// 1. 导入http模块
|
||||||
const http = require("http");
|
const http = require("http");
|
||||||
|
|
||||||
@@ -5,9 +7,7 @@ const http = require("http");
|
|||||||
const server = http.createServer();
|
const server = http.createServer();
|
||||||
|
|
||||||
// 3. 监听请求事件
|
// 3. 监听请求事件
|
||||||
server.on("request", (req, res) => {
|
server.on("request", async (req, res) => {
|
||||||
console.log(new Date(), "req.url", req.url);
|
|
||||||
|
|
||||||
//req-->request 请求对象, res-->response 响应对象
|
//req-->request 请求对象, res-->response 响应对象
|
||||||
// 通过响应头设置返回前台数据格式及编码。(解决中文乱码的问题)
|
// 通过响应头设置返回前台数据格式及编码。(解决中文乱码的问题)
|
||||||
// res.setHeader('Content-Type', 'text/html;charset=utf-8');
|
// res.setHeader('Content-Type', 'text/html;charset=utf-8');
|
||||||
@@ -41,21 +41,28 @@ server.on("request", (req, res) => {
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
result = {
|
result = {
|
||||||
code: 500,
|
success: false,
|
||||||
msg: "服务器内部错误",
|
msg: "服务器内部错误",
|
||||||
extra: {
|
data: null,
|
||||||
url: req.url,
|
// extra: {
|
||||||
method: req.method,
|
// url: req.url,
|
||||||
headers: req.headers,
|
// method: req.method,
|
||||||
req: Object.keys(req),
|
// headers: req.headers,
|
||||||
res: Object.keys(res)
|
// req: Object.keys(req),
|
||||||
}
|
// res: Object.keys(res)
|
||||||
|
// }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
res.write(JSON.stringify(result));
|
res.write(JSON.stringify(result));
|
||||||
|
|
||||||
|
// 模拟弱网等待时间
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, sleepTime);
|
||||||
|
})
|
||||||
|
|
||||||
//res.end()每次响应完,需要调用此方法 来结束响束
|
//res.end()每次响应完,需要调用此方法 来结束响束
|
||||||
res.end();
|
res.end();
|
||||||
|
console.log(new Date(), "req.url", req.url);
|
||||||
})
|
})
|
||||||
|
|
||||||
// 4. 监听端口,为了避免端口冲突,这里给一个本机端口
|
// 4. 监听端口,为了避免端口冲突,这里给一个本机端口
|
||||||
|
|||||||
@@ -100,7 +100,6 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Taro from '@tarojs/taro'
|
import Taro from '@tarojs/taro'
|
||||||
import { eventCenter, getCurrentInstance } from '@tarojs/taro'
|
|
||||||
import ENUM from '../../utils/const.js'
|
import ENUM from '../../utils/const.js'
|
||||||
import DebugComp from '../../components/DebugComp.vue'
|
import DebugComp from '../../components/DebugComp.vue'
|
||||||
|
|
||||||
@@ -120,39 +119,37 @@ export default {
|
|||||||
components: {
|
components: {
|
||||||
DebugComp
|
DebugComp
|
||||||
},
|
},
|
||||||
mounted() {
|
|
||||||
eventCenter.once(getCurrentInstance().router.onShow, () => {
|
|
||||||
console.log('onShow')
|
|
||||||
console.log("ENUM", ENUM)
|
|
||||||
|
|
||||||
this.userInfo = Taro.getStorageSync("userInfo");
|
onShow() {
|
||||||
this.displayUsername = this.userInfo?.username ?? "请登录";
|
console.log('onShow')
|
||||||
if (!this.userInfo) {
|
console.log("ENUM", ENUM)
|
||||||
console.log("用户未登录")
|
this.userInfo = Taro.getStorageSync("userInfo");
|
||||||
Taro.redirectTo({
|
this.displayUsername = this.userInfo?.username ?? "请登录";
|
||||||
url: '/pages/index/login'
|
if (!this.userInfo) {
|
||||||
})
|
console.log("用户未登录")
|
||||||
} else {
|
Taro.redirectTo({
|
||||||
const role = ENUM.user.role;
|
url: '/pages/index/login'
|
||||||
this.isVisitor = [
|
})
|
||||||
role.VISITOR,
|
} else {
|
||||||
].includes(this.userInfo.role);
|
const role = ENUM.user.role;
|
||||||
this.isUser = [
|
this.isVisitor = [
|
||||||
role.RESIDENTS_OWNER,
|
role.VISITOR,
|
||||||
role.RESIDENTS_MEMBER,
|
].includes(this.userInfo.role);
|
||||||
role.RESIDENTS_TENENT,
|
this.isUser = [
|
||||||
].includes(this.userInfo.role);
|
role.RESIDENTS_OWNER,
|
||||||
this.isAdmin = [
|
role.RESIDENTS_MEMBER,
|
||||||
role.ADMIN,
|
role.RESIDENTS_TENENT,
|
||||||
role.STAFF,
|
].includes(this.userInfo.role);
|
||||||
].includes(this.userInfo.role);
|
this.isAdmin = [
|
||||||
console.log(
|
role.ADMIN,
|
||||||
"isVisitor", this.isVisitor,
|
role.STAFF,
|
||||||
"isUser", this.isUser,
|
].includes(this.userInfo.role);
|
||||||
"isAdmin", this.isAdmin
|
console.log(
|
||||||
)
|
"isVisitor", this.isVisitor,
|
||||||
}
|
"isUser", this.isUser,
|
||||||
})
|
"isAdmin", this.isAdmin
|
||||||
|
)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
goCode() {
|
goCode() {
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ export default {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
let passwordHash = md5(this.password);
|
let passwordHash = md5(this.password);
|
||||||
|
Taro.showLoading({ title: '加载中' })
|
||||||
Taro.request({
|
Taro.request({
|
||||||
url: `${this.baseUrl}/user/login`,
|
url: `${this.baseUrl}/user/login`,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -54,18 +55,14 @@ export default {
|
|||||||
password: passwordHash,
|
password: passwordHash,
|
||||||
},
|
},
|
||||||
success: function (d) {
|
success: function (d) {
|
||||||
|
Taro.hideLoading()
|
||||||
let result = d.data;
|
let result = d.data;
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
// 登录成功
|
||||||
Taro.setStorageSync("userInfo", result.data.userInfo);
|
Taro.setStorageSync("userInfo", result.data.userInfo);
|
||||||
console.log("userInfo", Taro.getStorageSync("userInfo"))
|
console.log("userInfo", Taro.getStorageSync("userInfo"))
|
||||||
Taro.showToast({
|
Taro.switchTab({
|
||||||
title: "登录成功",
|
url: '/pages/index/index'
|
||||||
icon: 'success',
|
|
||||||
success: function () {
|
|
||||||
Taro.switchTab({
|
|
||||||
url: '/pages/index/index'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
@@ -76,6 +73,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: function () {
|
fail: function () {
|
||||||
|
Taro.hideLoading()
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
title: "请求失败",
|
title: "请求失败",
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Taro from '@tarojs/taro'
|
import Taro from '@tarojs/taro'
|
||||||
import { eventCenter, getCurrentInstance } from '@tarojs/taro'
|
|
||||||
import drawQrcode from '../../utils/qrcode/index'
|
import drawQrcode from '../../utils/qrcode/index'
|
||||||
import utils from '../../utils/utils'
|
import utils from '../../utils/utils'
|
||||||
|
|
||||||
@@ -84,8 +83,8 @@ export default {
|
|||||||
text: text,
|
text: text,
|
||||||
})
|
})
|
||||||
|
|
||||||
this.timeInterval = setInterval(this.updateTime, 1000);
|
|
||||||
this.updateTime();
|
this.updateTime();
|
||||||
|
this.timeInterval = setInterval(this.updateTime, 1000);
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
updateTime() {
|
updateTime() {
|
||||||
|
|||||||
Reference in New Issue
Block a user