10 changed files with 132 additions and 27 deletions
@ -1,19 +1,64 @@ |
|||||||
export const formatTime = (date: Date) => { |
export const formatTime = (date: Date) => { |
||||||
const year = date.getFullYear() |
const year = date.getFullYear(); |
||||||
const month = date.getMonth() + 1 |
const month = date.getMonth() + 1; |
||||||
const day = date.getDate() |
const day = date.getDate(); |
||||||
const hour = date.getHours() |
const hour = date.getHours(); |
||||||
const minute = date.getMinutes() |
const minute = date.getMinutes(); |
||||||
const second = date.getSeconds() |
const second = date.getSeconds(); |
||||||
|
|
||||||
return ( |
return `${[year, month, day].map(formatNumber).join("/")} ${[hour, minute, second].map(formatNumber).join(":")}`; |
||||||
[year, month, day].map(formatNumber).join('/') + |
}; |
||||||
' ' + |
|
||||||
[hour, minute, second].map(formatNumber).join(':') |
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; |
||||||
|
}; |
||||||
|
|
||||||
const formatNumber = (n: number) => { |
export const parseScene = (scene) => { |
||||||
const s = n.toString() |
if (scene) { |
||||||
return s[1] ? s : '0' + s |
return parseUrlArgsToArray(decodeURIComponent(scene)); |
||||||
|
} else { |
||||||
|
return null; |
||||||
} |
} |
||||||
|
}; |
||||||
|
Loading…
Reference in new issue