From abc4f65a8e7e77f7196158d662efd161fe6a86a5 Mon Sep 17 00:00:00 2001 From: limqhz <540344226@qq.com> Date: Wed, 4 Jan 2023 21:06:34 +0800 Subject: [PATCH] project init --- README.md | 2 - app.js | 10 ++ app.json | 15 +++ app.wxss | 10 ++ package-lock.json | 21 ++++ package.json | 22 ++++ project.config.json | 50 ++++++++++ sitemap.json | 7 ++ utils/api.js | 237 ++++++++++++++++++++++++++++++++++++++++++++ utils/util.js | 19 ++++ 10 files changed, 391 insertions(+), 2 deletions(-) create mode 100644 app.js create mode 100644 app.json create mode 100644 app.wxss create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 project.config.json create mode 100644 sitemap.json create mode 100644 utils/api.js create mode 100644 utils/util.js diff --git a/README.md b/README.md index 078eb5c..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,2 +0,0 @@ -# limqsh -review diff --git a/app.js b/app.js new file mode 100644 index 0000000..e4bc428 --- /dev/null +++ b/app.js @@ -0,0 +1,10 @@ +// app.js +import api from './utils/api.js'; +App({ + onLaunch() { + }, + + globalData: { + }, + $api: api, +}) diff --git a/app.json b/app.json new file mode 100644 index 0000000..a05673b --- /dev/null +++ b/app.json @@ -0,0 +1,15 @@ +{ + "pages": [ + "pages/task/index" + ], + "usingComponents": { + }, + "window": { + "backgroundTextStyle": "light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "奎因记账", + "navigationBarTextStyle": "black" + }, + "style": "v2", + "sitemapLocation": "sitemap.json" +} diff --git a/app.wxss b/app.wxss new file mode 100644 index 0000000..06c6fc9 --- /dev/null +++ b/app.wxss @@ -0,0 +1,10 @@ +/**app.wxss**/ +.container { + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + padding: 200rpx 0; + box-sizing: border-box; +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..c8a6368 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,21 @@ +{ + "name": "quinn-accounts", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "dayjs": { + "version": "1.11.7", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.7.tgz", + "integrity": "sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ==" + }, + "tdesign-miniprogram": { + "version": "0.33.0", + "resolved": "https://registry.npmjs.org/tdesign-miniprogram/-/tdesign-miniprogram-0.33.0.tgz", + "integrity": "sha512-dNerln9UN7YdYCZvWRCstvH2hEkmXtwboOGVKPY5ZXYgC8cG2eH4/buJ7j8l4Ci+jJLLSPQrGCj9e55Y83sw7g==", + "requires": { + "dayjs": "^1.10.7" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..50118fa --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "quinn-accounts", + "version": "1.0.0", + "description": "奎因清单", + "main": "app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/jiuzheyangyuan/quinn-accounts.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/jiuzheyangyuan/quinn-accounts/issues" + }, + "homepage": "https://github.com/jiuzheyangyuan/quinn-accounts#readme", + "dependencies": { + "tdesign-miniprogram": "^0.33.0" + } +} diff --git a/project.config.json b/project.config.json new file mode 100644 index 0000000..a46de64 --- /dev/null +++ b/project.config.json @@ -0,0 +1,50 @@ +{ + "description": "项目配置文件", + "packOptions": { + "ignore": [], + "include": [] + }, + "setting": { + "urlCheck": true, + "es6": true, + "enhance": true, + "postcss": true, + "preloadBackgroundData": false, + "minified": true, + "newFeature": false, + "coverView": true, + "nodeModules": true, + "autoAudits": false, + "showShadowRootInWxmlPanel": true, + "scopeDataCheck": false, + "uglifyFileName": false, + "checkInvalidKey": true, + "checkSiteMap": true, + "uploadWithSourceMap": true, + "compileHotReLoad": false, + "lazyloadPlaceholderEnable": false, + "useMultiFrameRuntime": true, + "useApiHook": true, + "useApiHostProcess": true, + "babelSetting": { + "ignore": [], + "disablePlugins": [], + "outputPath": "" + }, + "useIsolateContext": true, + "userConfirmedBundleSwitch": false, + "packNpmManually": false, + "packNpmRelationList": [], + "minifyWXSS": true, + "showES6CompileOption": false + }, + "compileType": "miniprogram", + "libVersion": "2.28.1", + "appid": "wxb1f499f0a173865b", + "projectname": "quinn-accounts", + "editorSetting": { + "tabIndent": "insertSpaces", + "tabSize": 4 + }, + "condition": {} +} \ No newline at end of file diff --git a/sitemap.json b/sitemap.json new file mode 100644 index 0000000..ca02add --- /dev/null +++ b/sitemap.json @@ -0,0 +1,7 @@ +{ + "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", + "rules": [{ + "action": "allow", + "page": "*" + }] +} \ No newline at end of file diff --git a/utils/api.js b/utils/api.js new file mode 100644 index 0000000..8a9f13c --- /dev/null +++ b/utils/api.js @@ -0,0 +1,237 @@ +//testURL +const BASE_URL = 'http://192.168.73.1:10393/mock/68a4cea5-9a96-4c33-b7b9-0f32269ef34f/test?apipost_id=872f12'; +//prodURL +// const BASE_URL = 'https://api.hongyutiyu.top'; + +function buildURL(url, needToken) { + let token = wx.getStorageSync('accessToken'); + + if (!needToken) { + return token ? url + (url.indexOf('?') >= 0 ? '&' : '?') + "access_token=" + token : url + } + return url + (url.indexOf('?') >= 0 ? '&' : '?'); +} + +export function fetchPost(url, params, needToken, multiple) { + url = buildURL(url, needToken); + + // 如果url不存在,返回错误 TODO + // if (!url) { + // return new Promise((resolve, reject) => { + // reject(); + // }) + // } + + console.log("网络请求", BASE_URL + url, params); + + // 如果上传图片 + if (multiple) { + return new Promise((resolve, reject) => { + wx.uploadFile({ + url: BASE_URL + url, + filePath: params.filePath, + name: 'image', + formData: {}, + success: function(response) { + console.log(response.data); + let res = JSON.parse(response.data); + console.log(res); + if (response.statusCode == 200) { + if (res.err_code == 0) { + // wx.hideLoading(); + resolve(res); + } else { + if (res.err_code == 10003 || res.err_code == 10006 || res.err_code == 20006) { + // wx.removeStorageSync('accessToken'); + // wx.redirectTo({ + // url: '/pages/login/index', + // }) + isUnLogin(); + reject(res); + return; + } else if (res.err_code == 20005) { + wx.removeStorageSync('accessToken'); + wx.removeStorageSync('history'); + wx.hideLoading(); + wx.showToast({ + title: res.err_msg, + icon: 'none', + duration: 2000 + }) + reject(res); + } else { + wx.hideLoading(); + wx.showToast({ + title: res.err_msg, + icon: 'none', + duration: 2000 + }) + reject(res); + } + } + } else { + wx.hideLoading(); + wx.showToast({ + title: '网络错误', + icon: 'none', + }) + reject(response); + } + }, + fail: function(err) { + console.log(err); + wx.hideLoading(); + wx.showToast({ + title: '网络错误', + icon: 'none', + }) + reject(response); + }, + }) + }) + } + + // 获取POST数据 + return new Promise((resolve, reject) => { + wx.request({ + url: BASE_URL + url, + data: params, + header: { + 'content-type': 'application/x-www-form-urlencoded' + }, + method: 'POST', + success: function(res) { + console.log("POST返回数据", url,res); + if (res.data.err_code == 0) { + wx.hideLoading(); + resolve(res.data); + } else { + if (res.data.err_code == 10003 || res.data.err_code == 10006 || res.data.err_code == 20006) { + // wx.removeStorageSync('accessToken'); + // wx.redirectTo({ + // url: '/pages/login/index', + // }) + reject(res); + return; + } else if (res.data.err_code == 30022) { + reject(res); + } else if (res.data.err_code == 20005) { + wx.removeStorageSync('accessToken'); + wx.removeStorageSync('history'); + wx.hideLoading(); + wx.showToast({ + title: res.data.err_msg, + icon: 'none', + duration: 2000 + }) + reject(res); + } else { + wx.hideLoading(); + wx.showToast({ + title: res.data.err_msg, + icon: 'none', + duration: 2000 + }) + reject(res); + } + + } + }, + fail: function(res) { + wx.hideLoading(); + wx.showToast({ + title: '网络错误', + icon: 'none', + duration: 2000 + }) + reject(res); + + }, + }) + }) +} + +// get请求 +export function fetchGet(url, params, needToken) { + url = buildURL(url, needToken); + // 如果url不存在,返回错误 TODO + // if (!url) { + // return new Promise((resolve, reject) => { + // reject(); + // }) + // } + + console.log("网络请求", BASE_URL + url, params); + return new Promise((resolve, reject) => { + wx.request({ + url: BASE_URL + url, + data: params, + method: 'GET', + success: function(res) { + console.log("GET返回数据", url, res); + if (res.statusCode == 200) { + if (res.data.err_code == 0) { + wx.hideLoading(); + resolve(res.data); + } else { + if (res.data.err_code == 10003 || res.data.err_code == 10006 || res.data.err_code == 20006) { + // isUnLogin(); + reject(res); + return; + } else if (res.data.err_code == 20005) { + wx.removeStorageSync('accessToken'); + wx.removeStorageSync('history'); + wx.hideLoading(); + wx.showToast({ + title: res.data.err_msg, + icon: 'none', + duration: 2000 + }) + reject(res); + } else { + wx.hideLoading(); + wx.showToast({ + title: res.data.err_msg, + icon: 'none', + duration: 2000 + }) + reject(res); + } + } + } else { + wx.hideLoading(); + reject(res) + wx.showToast({ + title: '网络错误', + icon: 'none', + duration: 2000 + }) + } + }, + fail: function(res) { + wx.hideLoading(); + reject(res) + wx.showToast({ + title: '网络错误', + icon: 'none', + duration: 2000 + }) + }, + }) + }) +} + +// 暴露接口 +export default { + /** + * 任务清单 + */ + taskList(params) { + return new Promise(x => { + let job = {data:{over:true}}; + x(job) + console.log(x + '请求成功'); + }) + // return fetchGet('', params, false); + }, +} diff --git a/utils/util.js b/utils/util.js new file mode 100644 index 0000000..764bc2c --- /dev/null +++ b/utils/util.js @@ -0,0 +1,19 @@ +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}` +} + +module.exports = { + formatTime +}