feat: 首页增加性能优化, 登录界面优化

This commit is contained in:
mayubo@gmail.com 2025-05-10 09:34:04 +08:00
parent ebe2ed6873
commit 1e4a8b8ed9
14 changed files with 162 additions and 112 deletions

View File

@ -237,19 +237,6 @@
}
},
onShow() {
if (uni.getStorageSync('city')) {
this.currentCity = {
city: uni.getStorageSync('city')
};
} else {
uni.setStorageSync('city', uni.getStorageSync('Usercity'))
}
},
methods: {
swipers(e) {
this.currentIdx = e.detail.current
@ -301,7 +288,7 @@
that.CommunityList = that.CommunityList.concat(res.rows || []);
that.flag = flag;
that.page_num = that.page_num + 1;
console.log(that.CommunityList);
});
},
getHostInfo() {
@ -334,6 +321,10 @@
if (idx == 0) {
this.getCommunityList();
} else if (idx == 1) {
if (!uni.getStorageSync('ctoken')) {
uni.navigateTo({ url: '/pages/login/login' });
return;
}
this.getServerList();
}
},
@ -434,8 +425,6 @@
if (res.rows.length) {
res.rows.forEach(item => {
item.icon_src = picUrl + item.icon_src
console.log(item.icon_src,'banner1');
})
this.tabList = res.rows
@ -500,26 +489,33 @@
mask: true
});
try {
const [provRes, cityRes, distRes] = await Promise.all([
this.getProvList(),
this.getCityList(),
this.getDistList(),
])
const proviceList = uni.getStorageSync('proviceList');
const cityList = uni.getStorageSync('cityList');
const businessList = uni.getStorageSync('businessList');
uni.setStorageSync('proviceList',provRes.rows)
uni.setStorageSync('cityList',cityRes.rows)
uni.setStorageSync('businessList',distRes.rows)
let cascaderOptions = null;
//
if (!proviceList || !cityList || !businessList) {
const [provRes, cityRes, distRes] = await Promise.all([
this.getProvList(),
this.getCityList(),
this.getDistList(),
])
let cascaderOptions = provRes.rows.map(province => ({
uni.setStorageSync('proviceList',provRes.rows)
uni.setStorageSync('cityList',cityRes.rows)
uni.setStorageSync('businessList',distRes.rows)
cascaderOptions = provRes?.rows.map(province => ({
value: province.city_id, // 使 city_id
label: province.name, // 使 name
children: cityRes.rows
children: cityRes?.rows
.filter(city => city.city_id === province.city_id) //
.map(city => ({
value: city.area_id, // 使 area_id
label: city.area_name, // 使 area_name
children: distRes.rows
children: distRes?.rows
.filter(district => district.area_id === city.area_id) //
.map(district => ({
value: district.business_id, // 使 business_id
@ -527,12 +523,34 @@
}))
}))
}))
console.log('接口返回数据处理 省市区', cascaderOptions);
};
console.log(cascaderOptions,'cascaderOptions');
//
if (!cascaderOptions) {
cascaderOptions = proviceList.map(province => ({
value: province.city_id, // 使 city_id
label: province.name, // 使 name
children: cityList
.filter(city => city.city_id === province.city_id) //
.map(city => ({
value: city.area_id, // 使 area_id
label: city.area_name, // 使 area_name
children: businessList
.filter(district => district.area_id === city.area_id) //
.map(district => ({
value: district.business_id, // 使 business_id
label: district.business_name // 使 business_name
}))
}))
}))
console.log('读缓存数据处理的省市区', cascaderOptions)
}
this.currentProviceCity = this.getProvinceCityId(cascaderOptions,uni.getStorageSync('city'))
await this.getButtonList()
await this.getBannerList()
@ -631,8 +649,6 @@
this.getHostInfo()
const meun = menuButtonInfo();
this.top = meun.height + meun.top;
},
onShow() {
if (uni.getStorageSync('city')) {

View File

@ -57,8 +57,10 @@
},
headerLoginClick() {
let _this = this;
uni.showLoading({
title: '登录中...',
mask: true
});
if (this.loginChannel === 'android' || this.loginChannel === 'ios') {
this.appLogin();
return;
@ -67,13 +69,11 @@
uni.login({
onlyAuthorize: true,
success: (res) => {
console.log('res', res);
// return
request(apiArr.login, 'POST', {
code: res.code,
phone: '',
password: '',
}).then((loginRes) => {
}, { silent: false }).then((loginRes) => {
//
uni.setStorageSync('ctoken', loginRes.token);
uni.setStorageSync('is_deal', loginRes.is_deal);
@ -83,9 +83,9 @@
//
request(apiArr.loginInfo, 'POST', {}, {
request(apiArr.loginInfo, 'POST', {
token: loginRes.token
}).then((res2) => {
}, { silent: false } ).then((res2) => {
if (res2.error) return;
// userId 使
uni.setStorageSync('userId', res2.user_id);
@ -93,8 +93,8 @@
uni.setStorageSync('shopId', res2.wshop_id);
this.isLogin = true;
})
uni.hideLoading();
}, (err) => {
uni.hideLoading();
console.log('登录接口错误', err);
})
}
@ -103,14 +103,13 @@
//
getPhoneNumber(event) {
let that = this
console.log('小程序登录获取手机号');
console.log('小程序登录获取手机号', event);
const { isLogin } = this;
console.log('获取信息', event);
if (event.detail.errMsg === "getPhoneNumber:ok") {
request(apiArr.loginGetPhone, 'POST', {
code: event.detail.code
}).then((res) => {
}, { silent: false }).then((res) => {
uni.hideLoading();
if (isLogin) {
uni.setStorageSync('phone', res.phone);
uni.showToast({
@ -134,6 +133,7 @@
}
})
} else {
uni.hideLoading();
uni.removeStorageSync('ctoken');
uni.removeStorageSync('userId');
uni.removeStorageSync('openId');
@ -148,14 +148,7 @@
// app
async appLogin() {
console.log('appLogin', this.userId);
console.log('passWord', this.passWord);
try {
uni.showLoading({
title: '登录中...',
mask: true
})
const loginRes = await request(apiArr.login, 'POST', {
code: '',
phone: this.userId,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -207,7 +207,6 @@ var _index2 = __webpack_require__(/*! ../../utils/index.js */ 167);
var _community = __webpack_require__(/*! ../../api/community.js */ 168);
var _doorToDoor = __webpack_require__(/*! ../../api/doorToDoor.js */ 169);
var _area = __webpack_require__(/*! ../../api/area.js */ 170);
var _components$data$onSh;
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
@ -217,7 +216,7 @@ var nav = function nav() {
}).bind(null, __webpack_require__)).catch(__webpack_require__.oe);
};
//1.导入组件
var _default = (_components$data$onSh = {
var _default = {
components: {
nav: nav
},
@ -295,15 +294,6 @@ var _default = (_components$data$onSh = {
// },
]), (0, _defineProperty2.default)(_ref, "title", 'Hello'), (0, _defineProperty2.default)(_ref, "currentCity", ""), (0, _defineProperty2.default)(_ref, "currentProviceCity", ""), _ref;
},
onShow: function onShow() {
if (uni.getStorageSync('city')) {
this.currentCity = {
city: uni.getStorageSync('city')
};
} else {
uni.setStorageSync('city', uni.getStorageSync('Usercity'));
}
},
methods: {
swipers: function swipers(e) {
this.currentIdx = e.detail.current;
@ -354,7 +344,6 @@ var _default = (_components$data$onSh = {
that.CommunityList = that.CommunityList.concat(res.rows || []);
that.flag = flag;
that.page_num = that.page_num + 1;
console.log(that.CommunityList);
});
},
getHostInfo: function getHostInfo() {
@ -387,6 +376,12 @@ var _default = (_components$data$onSh = {
if (idx == 0) {
this.getCommunityList();
} else if (idx == 1) {
if (!uni.getStorageSync('ctoken')) {
uni.navigateTo({
url: '/pages/login/login'
});
return;
}
this.getServerList();
}
},
@ -471,7 +466,6 @@ var _default = (_components$data$onSh = {
if (res.rows.length) {
res.rows.forEach(function (item) {
item.icon_src = _index2.picUrl + item.icon_src;
console.log(item.icon_src, 'banner1');
});
_this3.tabList = res.rows;
}
@ -573,7 +567,7 @@ var _default = (_components$data$onSh = {
init: function init() {
var _this4 = this;
return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
var _yield$Promise$all, _yield$Promise$all2, provRes, cityRes, distRes, cascaderOptions;
var proviceList, cityList, businessList, cascaderOptions, _yield$Promise$all, _yield$Promise$all2, provRes, cityRes, distRes;
return _regenerator.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
@ -583,9 +577,17 @@ var _default = (_components$data$onSh = {
mask: true
});
_context4.prev = 1;
_context4.next = 4;
proviceList = uni.getStorageSync('proviceList');
cityList = uni.getStorageSync('cityList');
businessList = uni.getStorageSync('businessList');
cascaderOptions = null; // 有缓存数据时 不进行接口请求
if (!(!proviceList || !cityList || !businessList)) {
_context4.next = 19;
break;
}
_context4.next = 9;
return Promise.all([_this4.getProvList(), _this4.getCityList(), _this4.getDistList()]);
case 4:
case 9:
_yield$Promise$all = _context4.sent;
_yield$Promise$all2 = (0, _slicedToArray2.default)(_yield$Promise$all, 3);
provRes = _yield$Promise$all2[0];
@ -594,13 +596,13 @@ var _default = (_components$data$onSh = {
uni.setStorageSync('proviceList', provRes.rows);
uni.setStorageSync('cityList', cityRes.rows);
uni.setStorageSync('businessList', distRes.rows);
cascaderOptions = provRes.rows.map(function (province) {
cascaderOptions = provRes === null || provRes === void 0 ? void 0 : provRes.rows.map(function (province) {
return {
value: province.city_id,
// 使用 city_id 作为省的值
label: province.name,
// 使用 name 作为省的显示文本
children: cityRes.rows.filter(function (city) {
children: cityRes === null || cityRes === void 0 ? void 0 : cityRes.rows.filter(function (city) {
return city.city_id === province.city_id;
}) // 注意:这里需要确认关联字段
.map(function (city) {
@ -609,7 +611,7 @@ var _default = (_components$data$onSh = {
// 使用 area_id 作为市的值
label: city.area_name,
// 使用 area_name 作为市的显示文本
children: distRes.rows.filter(function (district) {
children: distRes === null || distRes === void 0 ? void 0 : distRes.rows.filter(function (district) {
return district.area_id === city.area_id;
}) // 注意:这里需要确认关联字段
.map(function (district) {
@ -624,28 +626,65 @@ var _default = (_components$data$onSh = {
};
});
console.log(cascaderOptions, 'cascaderOptions');
_this4.currentProviceCity = _this4.getProvinceCityId(cascaderOptions, uni.getStorageSync('city'));
_context4.next = 17;
return _this4.getButtonList();
case 17:
_context4.next = 19;
return _this4.getBannerList();
console.log('接口返回数据处理 省市区', cascaderOptions);
case 19:
uni.hideLoading();
;
// 如果读的接口返回数据,则不二次进行处理, 否则对缓存数据进行二次处理
if (!cascaderOptions) {
cascaderOptions = proviceList.map(function (province) {
return {
value: province.city_id,
// 使用 city_id 作为省的值
label: province.name,
// 使用 name 作为省的显示文本
children: cityList.filter(function (city) {
return city.city_id === province.city_id;
}) // 注意:这里需要确认关联字段
.map(function (city) {
return {
value: city.area_id,
// 使用 area_id 作为市的值
label: city.area_name,
// 使用 area_name 作为市的显示文本
children: businessList.filter(function (district) {
return district.area_id === city.area_id;
}) // 注意:这里需要确认关联字段
.map(function (district) {
return {
value: district.business_id,
// 使用 business_id 作为区的值
label: district.business_name // 使用 business_name 作为区的显示文本
};
})
};
})
};
});
console.log('读缓存数据处理的省市区', cascaderOptions);
}
_this4.currentProviceCity = _this4.getProvinceCityId(cascaderOptions, uni.getStorageSync('city'));
_context4.next = 24;
return _this4.getButtonList();
case 24:
_context4.next = 26;
return _this4.getBannerList();
case 26:
uni.hideLoading();
_context4.next = 33;
break;
case 22:
_context4.prev = 22;
case 29:
_context4.prev = 29;
_context4.t0 = _context4["catch"](1);
uni.hideLoading();
console.log('获取省市区信息异常', _context4.t0);
case 26:
case 33:
case "end":
return _context4.stop();
}
}
}, _callee4, null, [[1, 22]]);
}, _callee4, null, [[1, 29]]);
}))();
},
getProvinceCityId: function getProvinceCityId(areaList, cityName) {
@ -762,27 +801,29 @@ var _default = (_components$data$onSh = {
this.getHostInfo();
var meun = (0, _index2.menuButtonInfo)();
this.top = meun.height + meun.top;
}
}, (0, _defineProperty2.default)(_components$data$onSh, "onShow", function onShow() {
if (uni.getStorageSync('city')) {
var obj = {
city: uni.getStorageSync('city')
};
this.currentCity = obj;
} else {
uni.setStorageSync('city', uni.getStorageSync('Usercity'));
}
}), (0, _defineProperty2.default)(_components$data$onSh, "onReachBottom", function onReachBottom() {
if (this.current == 0) {
if (this.flag) {
this.getCommunityList();
},
onShow: function onShow() {
if (uni.getStorageSync('city')) {
var obj = {
city: uni.getStorageSync('city')
};
this.currentCity = obj;
} else {
uni.setStorageSync('city', uni.getStorageSync('Usercity'));
}
} else if (this.current == 1) {
if (this.flag) {
this.getServerList();
},
onReachBottom: function onReachBottom() {
if (this.current == 0) {
if (this.flag) {
this.getCommunityList();
}
} else if (this.current == 1) {
if (this.flag) {
this.getServerList();
}
}
}
}), _components$data$onSh);
};
exports.default = _default;
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./node_modules/@dcloudio/uni-mp-weixin/dist/index.js */ 2)["default"], __webpack_require__(/*! ./node_modules/@dcloudio/uni-mp-weixin/dist/wx.js */ 1)["default"]))