From 635bc8c7e8a3ff2555cf30c68cb92fa3893d26cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B9=BF=E5=92=8Csa0ChunLuyu?= Date: Thu, 30 Jun 2022 18:04:31 +0800 Subject: [PATCH] no message --- lu/axios.js | 5 ++++- lu/format.js | 17 +++++++++++++++++ lu/index.js | 10 ++++++---- 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 lu/format.js diff --git a/lu/axios.js b/lu/axios.js index 03fda87..c6c304e 100644 --- a/lu/axios.js +++ b/lu/axios.js @@ -13,7 +13,10 @@ export const $post = async ({ data = {} }) => { let token = getToken() ? getToken() : ''; - if (noLogin.indexOf(url) === -1 && token === '') return false + if (noLogin.indexOf(url) === -1 && token === '') { + uni.$lu.toast("请登录") + return false + } if (requests[url]) return false; requests[url] = true let res = await uni.request({ diff --git a/lu/format.js b/lu/format.js new file mode 100644 index 0000000..f8b8678 --- /dev/null +++ b/lu/format.js @@ -0,0 +1,17 @@ +const format = (value = Date.now(), format = "Y-M-D h:m:s") => { + const formatNumber = n => `0${n}`.slice(-2); + const date = new Date(value); + const formatList = ["Y", "M", "D", "h", "m", "s"]; + const resultList = []; + resultList.push(date.getFullYear().toString()); + resultList.push(formatNumber(date.getMonth() + 1)); + resultList.push(formatNumber(date.getDate())); + resultList.push(formatNumber(date.getHours())); + resultList.push(formatNumber(date.getMinutes())); + resultList.push(formatNumber(date.getSeconds())); + for (let i = 0; i < resultList.length; i++) { + format = format.replace(formatList[i], resultList[i]); + } + return format; +} +export default format diff --git a/lu/index.js b/lu/index.js index 4c85eec..f72fdab 100644 --- a/lu/index.js +++ b/lu/index.js @@ -1,4 +1,6 @@ -import toast from './toast.js'; -export default { - toast, -}; \ No newline at end of file +import toast from './toast.js'; +import format from './format.js'; +export default { + toast, + format +};