Commit 5f616d0f by 张立顺

feat 免登录查看页面功能开发

1 parent e43d8250
import { setSessionId, setUserInfo } from '~/utils/cache/storageApi' import { setSessionId, setUserInfo } from '~/utils/cache/storageApi'
import USERAPI from '~/api/usersApi/index' import USERAPI from '~/api/usersApi/index'
const setRouteData = targetPath => { const setRouteData = targetPath => {
targetPath = decodeURIComponent(targetPath)
console.log(targetPath, 'targetPath');
let [url, query] = targetPath.split('?'), let [url, query] = targetPath.split('?'),
obj = {} obj = {}
console.log(query, 'query');
if (query) { if (query) {
var list = query.split('&') || [] var list = query.split('&') || []
console.log(list,list);
list.forEach(item => { list.forEach(item => {
const [key, val] = item.split('=') const [key, val] = item.split('=')
obj[key] = val obj[key] = val
}) })
} }
console.log(obj, url);
return { return {
url, url,
obj obj
...@@ -21,6 +26,7 @@ const selectAccountLogin = ({ id, sessionId }) => { ...@@ -21,6 +26,7 @@ const selectAccountLogin = ({ id, sessionId }) => {
id, id,
sessionId sessionId
}).then(({ code, data, message }) => { }).then(({ code, data, message }) => {
console.log(code, 'selectAccountLogin');
if (code == '0') { if (code == '0') {
console.log(data) console.log(data)
setLoginInfo(data.loginUserInfoList[0], data.sessionId) setLoginInfo(data.loginUserInfoList[0], data.sessionId)
...@@ -56,9 +62,11 @@ const setLoginInfo = (userInfo, sessionId) => { ...@@ -56,9 +62,11 @@ const setLoginInfo = (userInfo, sessionId) => {
} }
}) })
} }
// debugger
// 自动创建服务中心 // 自动创建服务中心
initServiceCenter() initServiceCenter()
setUserInfo(userInfo) setUserInfo(userInfo)
// debugger
setSessionId(sessionId) setSessionId(sessionId)
loginSuccess() loginSuccess()
} }
...@@ -68,8 +76,10 @@ const initServiceCenter = () => { ...@@ -68,8 +76,10 @@ const initServiceCenter = () => {
/**成功跳转 */ /**成功跳转 */
const loginSuccess = () => { const loginSuccess = () => {
const { const {
options: { targetPath } options: { targetPath },
options,
} = wx.$router.getPageInstance() } = wx.$router.getPageInstance()
console.log(options, 'loginSuccess');
if (targetPath) { if (targetPath) {
const { url, obj } = setRouteData(targetPath) const { url, obj } = setRouteData(targetPath)
wx.$router.reLaunch(url, obj) wx.$router.reLaunch(url, obj)
......
...@@ -15,12 +15,12 @@ Page({ ...@@ -15,12 +15,12 @@ Page({
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad(options) {}, onLoad(options) { },
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
onReady() {}, onReady() { },
/** /**
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
...@@ -67,22 +67,22 @@ Page({ ...@@ -67,22 +67,22 @@ Page({
/** /**
* 生命周期函数--监听页面隐藏 * 生命周期函数--监听页面隐藏
*/ */
onHide() {}, onHide() { },
/** /**
* 生命周期函数--监听页面卸载 * 生命周期函数--监听页面卸载
*/ */
onUnload() {}, onUnload() { },
/** /**
* 页面相关事件处理函数--监听用户下拉动作 * 页面相关事件处理函数--监听用户下拉动作
*/ */
onPullDownRefresh() {}, onPullDownRefresh() { },
/** /**
* 页面上拉触底事件的处理函数 * 页面上拉触底事件的处理函数
*/ */
onReachBottom() {}, onReachBottom() { },
arrToObj(list) { arrToObj(list) {
if (!Array.isArray(list)) { if (!Array.isArray(list)) {
return {} return {}
...@@ -178,6 +178,12 @@ Page({ ...@@ -178,6 +178,12 @@ Page({
} }
USERAPI.accountLogin(params) USERAPI.accountLogin(params)
.then(({ code, data, message }) => { .then(({ code, data, message }) => {
this.options = {
...this.options,
...obj
}
console.log(this.options, 'this.options');
// debugger
if (code == '0') { if (code == '0') {
const { sessionId, loginUserInfoList } = data const { sessionId, loginUserInfoList } = data
var routeParams = {} var routeParams = {}
...@@ -199,6 +205,9 @@ Page({ ...@@ -199,6 +205,9 @@ Page({
// this.options.targetPath = '/pages/tab/output/output' + "?" + list.join("&") // this.options.targetPath = '/pages/tab/output/output' + "?" + list.join("&")
this.options.targetPath = '/pages/tab/outputValue/outputValue' + '?' + list.join('&') this.options.targetPath = '/pages/tab/outputValue/outputValue' + '?' + list.join('&')
} }
// if (obj.url == '/packagesList/packageOutput/pages/summary') {
// }
setLoginInfo(loginUserInfoList[0], sessionId) setLoginInfo(loginUserInfoList[0], sessionId)
} else { } else {
wx.$api.showToast(message || '系统异常') wx.$api.showToast(message || '系统异常')
......
...@@ -50,19 +50,26 @@ Page({ ...@@ -50,19 +50,26 @@ Page({
} }
}, },
initTime() { initTime(beginDateStr) {
// 获取当前日期 // 获取当前日期
// const currentDate = beginDateStr ? new Date(beginDateStr) : new Date()
const currentDate = new Date() const currentDate = new Date()
let today = currentDate.format('yyyy-MM-dd') let today = currentDate.format('yyyy-MM-dd')
let NewYearDay = currentDate.format('yyyy') let NewYearDay = currentDate.format('yyyy')
let month = currentDate.getMonth() + 1 < 10 ? ('0' + (currentDate.getMonth() + 1)) : currentDate.getMonth() + 1 let month = currentDate.getMonth() + 1 < 10 ? ('0' + (currentDate.getMonth() + 1)) : currentDate.getMonth() + 1
let firstDayOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).format('yyyy-MM-dd') let firstDayOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).format('yyyy-MM-dd')
// console.log(NewYearDay) // console.log(NewYearDay)
let endDateStr
if (beginDateStr) {
let date = new Date(beginDateStr)
firstDayOfMonth = new Date(date.getFullYear(), date.getMonth(), 1).format('yyyy-MM-dd')
endDateStr = this.getLastDayOfMonth(beginDateStr)
console.log(endDateStr, 'endDateStr');
}
this.setData({ this.setData({
dateObj: { dateObj: {
beginDateStr: firstDayOfMonth, beginDateStr: firstDayOfMonth,
endDateStr: today, endDateStr: endDateStr || today,
today: today, today: today,
pointUnit: 2, // 1日,2月,默认日 pointUnit: 2, // 1日,2月,默认日
type: 'month', type: 'month',
...@@ -72,7 +79,28 @@ Page({ ...@@ -72,7 +79,28 @@ Page({
} }
}) })
}, },
getLastDayOfMonth(beginDateStr) {
console.log(beginDateStr, 'beginDateStr');
// 将日期字符串转换为Date对象
var beginDate = new Date(beginDateStr);
console.log(beginDate, 'beginDate');
// 获取给定日期的月份和年份
var month = beginDate.getMonth();
var year = beginDate.getFullYear();
// 构建下一个月的第一天
var nextMonth = new Date(year, month + 1, 1);
// 使用下一个月的第一天的前一天作为当前月的最后一天
var lastDay = new Date(nextMonth.getTime() - 1);
// // 提取最后一天的日期部分并返回
// var lastDayOfMonth = lastDay.getDate();
// 提取最后一天的年份、月份和日期,并格式化为字符串
var lastDayOfMonth = lastDay.toISOString().split('T')[0];
return lastDayOfMonth;
// return lastDayOfMonth;
},
getLastDay(year, month) { getLastDay(year, month) {
var new_year = year //取当前的年份 var new_year = year //取当前的年份
var new_month = month++ //取下一个月的第一天,方便计算(最后一天不固定) var new_month = month++ //取下一个月的第一天,方便计算(最后一天不固定)
...@@ -337,8 +365,13 @@ Page({ ...@@ -337,8 +365,13 @@ Page({
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad(options) { onLoad(options) {
},
onRoute(options) {
console.log(options, 'options');
wx.$api.showLoading('加载中...') wx.$api.showLoading('加载中...')
this.initTime() console.log(options, 'businessAnalysis');
this.initTime(options?.beginDateStr || '')
this.freshPage() this.freshPage()
this.getPurchaseList() this.getPurchaseList()
new setTimeout(() => { new setTimeout(() => {
......
{ {
"appid": "wx2c28337db96364d2", "appid": "wx2c28337db96364d2",
"projectname": "business-assistant", "projectname": "business-assistant",
"compileType": "miniprogram", "compileType": "miniprogram",
"packOptions": { "packOptions": {
"ignore": [], "ignore": [],
"include": [] "include": []
}, },
"condition": { "condition": {
"miniprogram": { "miniprogram": {
"list": [ "list": [
{ {
"name": "看产值", "name": "看产值",
"pathName": "pages/tab/output/output", "pathName": "pages/tab/output/output",
"query": "", "query": "",
"launchMode": "default", "launchMode": "default",
"scene": null "scene": null
}, },
{ {
"name": "携带目标页面", "name": "携带目标页面",
"pathName": "login/loading/loading", "pathName": "login/loading/loading",
"query": "url=%2Fpages%2Ftab%2Fmine%2Fmine%3Fid%3D123", "query": "url=%2Fpages%2Ftab%2Fmine%2Fmine%3Fid%3D123",
"launchMode": "default", "launchMode": "default",
"scene": null "scene": null
}, },
{ {
"name": "选择账号", "name": "选择账号",
"pathName": "login/accountItems/accountItems", "pathName": "login/accountItems/accountItems",
"query": "", "query": "",
"launchMode": "default", "launchMode": "default",
"scene": null "scene": null
}, },
{ {
"name": "个人中心", "name": "个人中心",
"pathName": "pages/tab/mine/mine", "pathName": "pages/tab/mine/mine",
"query": "", "query": "",
"launchMode": "default", "launchMode": "default",
"scene": null "scene": null
}, },
{ {
"name": "", "name": "",
"pathName": "login/index/index", "pathName": "login/index/index",
"query": "", "query": "",
"launchMode": "default", "launchMode": "default",
"scene": null "scene": null
}, },
{ {
"name": "客户管理", "name": "客户管理",
"pathName": "pages/mineDetail/customerManagement/customerManagement", "pathName": "pages/mineDetail/customerManagement/customerManagement",
"query": "", "query": "",
"launchMode": "default", "launchMode": "default",
"scene": null "scene": null
}, },
{ {
"name": "消息盒子", "name": "消息盒子",
"pathName": "pages/mineDetail/messageBox/messageBox", "pathName": "pages/mineDetail/messageBox/messageBox",
"query": "", "query": "",
"launchMode": "default", "launchMode": "default",
"scene": null "scene": null
} }
] ]
} }
}, },
"setting": { "setting": {
"urlCheck": true, "urlCheck": true,
"coverView": true, "coverView": true,
"postcss": true, "postcss": true,
"lazyloadPlaceholderEnable": true, "lazyloadPlaceholderEnable": true,
"minified": true, "minified": true,
"useIsolateContext": false, "useIsolateContext": false,
"enhance": true, "enhance": true,
"showShadowRootInWxmlPanel": true, "showShadowRootInWxmlPanel": true,
"packNpmManually": true, "packNpmManually": true,
"packNpmRelationList": [ "packNpmRelationList": [
{ {
"packageJsonPath": "./package.json", "packageJsonPath": "./package.json",
"miniprogramNpmDistDir": "./" "miniprogramNpmDistDir": "./"
} }
], ],
"useStaticServer": true, "useStaticServer": true,
"ignoreUploadUnusedFiles": true, "ignoreUploadUnusedFiles": true,
"babelSetting": { "babelSetting": {
"ignore": [], "ignore": [],
"disablePlugins": [], "disablePlugins": [],
"outputPath": "" "outputPath": ""
}, },
"useCompilerPlugins": [ "useCompilerPlugins": [
"sass" "sass"
], ],
"condition": false "condition": false
}, },
"editorSetting": { "editorSetting": {
"tabIndent": "insertSpaces", "tabIndent": "insertSpaces",
"tabSize": 2 "tabSize": 2
} },
"libVersion": "2.27.2"
} }
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!