10 changed files with 132 additions and 27 deletions
@ -1,19 +1,64 @@
@@ -1,19 +1,64 @@
|
||||
export const formatTime = (date: Date) => { |
||||
const year = date.getFullYear() |
||||
const month = date.getMonth() + 1 |
||||
const day = date.getDate() |
||||
const hour = date.getHours() |
||||
const minute = date.getMinutes() |
||||
const second = date.getSeconds() |
||||
const year = date.getFullYear(); |
||||
const month = date.getMonth() + 1; |
||||
const day = date.getDate(); |
||||
const hour = date.getHours(); |
||||
const minute = date.getMinutes(); |
||||
const second = date.getSeconds(); |
||||
|
||||
return ( |
||||
[year, month, day].map(formatNumber).join('/') + |
||||
' ' + |
||||
[hour, minute, second].map(formatNumber).join(':') |
||||
) |
||||
} |
||||
return `${[year, month, day].map(formatNumber).join("/")} ${[hour, minute, second].map(formatNumber).join(":")}`; |
||||
}; |
||||
|
||||
const formatNumber = (n: number) => { |
||||
const s = n.toString() |
||||
return s[1] ? s : '0' + s |
||||
} |
||||
export const formatNumber = (n: number) => { |
||||
const s = n.toString(); |
||||
return s[1] ? s : `0${s}`; |
||||
}; |
||||
|
||||
/** |
||||
* 获取当前页面路径 |
||||
* @returns string |
||||
*/ |
||||
export const getCurrentPageUrl = function () { |
||||
const pages = getCurrentPages(); |
||||
const currentPage = pages[pages.length - 1]; |
||||
const url = `/${currentPage.route}`; |
||||
return url; |
||||
}; |
||||
|
||||
/** |
||||
* 获取当前页面路径 & 参数 |
||||
* @returns string |
||||
*/ |
||||
export const getCurrentPageUrlWithArgs = function () { |
||||
const pages = getCurrentPages(); |
||||
const currentPage = pages[pages.length - 1]; |
||||
const url = currentPage.route; |
||||
const options = currentPage.options; |
||||
let urlWithArgs = `/${url}?`; |
||||
for (const key in options) { |
||||
const value = options[key]; |
||||
urlWithArgs += `${key}=${value}&`; |
||||
} |
||||
urlWithArgs = urlWithArgs.substring(0, urlWithArgs.length - 1); |
||||
return urlWithArgs; |
||||
}; |
||||
|
||||
const parseUrlArgsToArray = (urlArgs) => { |
||||
urlArgs = urlArgs.split("&"); |
||||
const results = {}; |
||||
urlArgs.forEach((arg) => { |
||||
arg = arg.split("="); |
||||
if (arg[0] && arg[1]) { |
||||
results[arg[0]] = arg[1]; |
||||
} |
||||
}); |
||||
return results; |
||||
}; |
||||
|
||||
export const parseScene = (scene) => { |
||||
if (scene) { |
||||
return parseUrlArgsToArray(decodeURIComponent(scene)); |
||||
} else { |
||||
return null; |
||||
} |
||||
}; |
||||
|
Loading…
Reference in new issue