first commit
This commit is contained in:
3
utils/config.js
Normal file
3
utils/config.js
Normal file
@@ -0,0 +1,3 @@
|
||||
// 在config.js
|
||||
const requestUrl = "http://127.0.0.1:8000";
|
||||
export { requestUrl };
|
||||
61
utils/util.js
Normal file
61
utils/util.js
Normal file
@@ -0,0 +1,61 @@
|
||||
const formatTime = 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()
|
||||
|
||||
return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
|
||||
}
|
||||
|
||||
const formatNumber = n => {
|
||||
n = n.toString()
|
||||
return n[1] ? n : `0${n}`
|
||||
}
|
||||
|
||||
function checkFile(path) {
|
||||
let fs = wx.getFileSystemManager();
|
||||
fs.access({
|
||||
path: `${wx.env.USER_DATA_PATH}/usr/images/1.png`,
|
||||
success(res) {
|
||||
// 文件存在
|
||||
console.log("存在")
|
||||
},
|
||||
fail(res) {
|
||||
// 文件不存在或其他错误
|
||||
console.error(res)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function checkDir() {
|
||||
let fs = wx.getFileSystemManager()
|
||||
fs.access({
|
||||
path: `${wx.env.USER_DATA_PATH}/images`,
|
||||
success(res) {
|
||||
// 文件存在
|
||||
console.log(res)
|
||||
return;
|
||||
},
|
||||
fail(res) {
|
||||
console.log(res)
|
||||
// 文件不存在或其他错误
|
||||
fs.mkdir({
|
||||
dirPath: `${wx.env.USER_DATA_PATH}/images`,
|
||||
recursive: false,
|
||||
success(res) {
|
||||
console.log(res)
|
||||
},
|
||||
fail(res) {
|
||||
console.error(res)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
module.exports = {
|
||||
formatTime,
|
||||
checkFile,
|
||||
checkDir
|
||||
}
|
||||
Reference in New Issue
Block a user