| @@ -1,7 +1,10 @@ | |||||
| // app.ts | |||||
| App<IAppOption>({ | |||||
| globalData: {}, | |||||
| // import Request from '../miniprogram/utils/request.js' | |||||
| App({ | |||||
| globalData: { | |||||
| }, | |||||
| onLaunch() { | onLaunch() { | ||||
| const appId = 'wxf288a9b8167ff2ca' | |||||
| // 展示本地存储能力 | // 展示本地存储能力 | ||||
| const logs = wx.getStorageSync('logs') || [] | const logs = wx.getStorageSync('logs') || [] | ||||
| logs.unshift(Date.now()) | logs.unshift(Date.now()) | ||||
| @@ -10,9 +13,20 @@ App<IAppOption>({ | |||||
| // 登录 | // 登录 | ||||
| wx.login({ | wx.login({ | ||||
| success: res => { | success: res => { | ||||
| console.log(res.code) | |||||
| // 发送 res.code 到后台换取 openId, sessionKey, unionId | // 发送 res.code 到后台换取 openId, sessionKey, unionId | ||||
| console.log(res.code) | |||||
| }, | }, | ||||
| }) | }) | ||||
| const doLogin = () => { | |||||
| Request.get({ | |||||
| url: '/login' | |||||
| }).then(res => { | |||||
| console.log(res); | |||||
| }).catch(err => { | |||||
| console.log(err); | |||||
| wx.showToast() | |||||
| }) | |||||
| } | |||||
| }, | }, | ||||
| }) | }) | ||||
| @@ -1,6 +1,7 @@ | |||||
| // index.ts | // index.ts | ||||
| // 获取应用实例 | // 获取应用实例 | ||||
| const app = getApp<IAppOption>() | |||||
| const app = getApp() | |||||
| import Request from '../../utils/request' | |||||
| Page({ | Page({ | ||||
| data: { | data: { | ||||
| @@ -24,6 +25,7 @@ Page({ | |||||
| canIUseGetUserProfile: true | canIUseGetUserProfile: true | ||||
| }) | }) | ||||
| } | } | ||||
| }, | }, | ||||
| getUserProfile() { | getUserProfile() { | ||||
| // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 | // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 | ||||
| @@ -38,7 +40,9 @@ Page({ | |||||
| } | } | ||||
| }) | }) | ||||
| }, | }, | ||||
| getUserInfo(e: any) { | |||||
| getUserInfo(e) { | |||||
| // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息 | // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息 | ||||
| console.log(e) | console.log(e) | ||||
| this.setData({ | this.setData({ | ||||
| @@ -8,7 +8,7 @@ Page({ | |||||
| }, | }, | ||||
| onLoad() { | onLoad() { | ||||
| this.setData({ | this.setData({ | ||||
| logs: (wx.getStorageSync('logs') || []).map((log: string) => { | |||||
| logs: (wx.getStorageSync('logs') || []).map(log => { | |||||
| return { | return { | ||||
| date: formatTime(new Date(log)), | date: formatTime(new Date(log)), | ||||
| timeStamp: log | timeStamp: log | ||||
| @@ -0,0 +1,120 @@ | |||||
| const url = 'https://gpttest.malls.iformall.com/C' | |||||
| class Request { | |||||
| constructor(address) { | |||||
| if (address) { | |||||
| this.address = address; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * 配置 | |||||
| */ | |||||
| /** | |||||
| * 请求路径前缀 | |||||
| */ | |||||
| address = url; | |||||
| /** | |||||
| * 请求头 | |||||
| */ | |||||
| headers = { | |||||
| "Content-Type": "application/json;charset=UTF-8", | |||||
| token: "" | |||||
| }; | |||||
| /** | |||||
| * 设置token | |||||
| * @param {*} token | |||||
| */ | |||||
| setToken(token) { | |||||
| this.headers.token = token; | |||||
| } | |||||
| /** | |||||
| * @description get | |||||
| * @param {*}param url & param | |||||
| * @method Request.get({url: url}).then(res=>{}).catch(err=>{}) | |||||
| */ | |||||
| get({ url, data, headers }) { | |||||
| headers = { ...this.headers, ...headers }; | |||||
| url = `${this.address}${url}`; | |||||
| return new Promise((resolve, reject) => { | |||||
| wx.request({ | |||||
| url: url, | |||||
| header: headers, | |||||
| data: data, | |||||
| method: "Get", | |||||
| success: res => { | |||||
| this.responseMap(res, resolve, reject); | |||||
| }, | |||||
| fail: err => { | |||||
| console.log(err) | |||||
| if (err.errMsg == 'request:fail timeout') { | |||||
| err.errMsg = '请求超时,请检查您的网络设置!' | |||||
| } else if (err.errMsg == 'request:fail') { | |||||
| err.errMsg = '未检查到您的网络,请检查您的网络设置!' | |||||
| } else if (err.errMsg == 'request:fail request connect error') { | |||||
| err.errMsg = '连接失败' | |||||
| } | |||||
| reject(err); | |||||
| } | |||||
| }); | |||||
| }); | |||||
| } | |||||
| /** | |||||
| * @description post | |||||
| * @param {*}param url & param | |||||
| * @method Request.post({url: url,data: {}}).then(res=>{}).catch(err=>{}) | |||||
| */ | |||||
| post({ url, data, headers }) { | |||||
| headers = { ...this.headers, ...headers }; | |||||
| url = `${this.address}${url}`; | |||||
| return new Promise((resolve, reject) => { | |||||
| wx.request({ | |||||
| url: url, | |||||
| header: headers, | |||||
| data: data, | |||||
| method: "POST", | |||||
| success: res => { | |||||
| this.responseMap(res, resolve, reject); | |||||
| }, | |||||
| fail: err => { | |||||
| if (err.errMsg == 'request:fail timeout') { | |||||
| err.errMsg = '请求超时,请检查您的网络设置!' | |||||
| } else if (err.errMsg == 'request:fail') { | |||||
| err.errMsg = '未检查到您的网络,请检查您的网络设置!' | |||||
| } else if (err.errMsg == 'request:fail request connect error') { | |||||
| err.errMsg = '连接失败' | |||||
| } | |||||
| reject(err); | |||||
| }, | |||||
| complete: res => { } | |||||
| }); | |||||
| }); | |||||
| } | |||||
| /** | |||||
| * 过滤 请求信息 | |||||
| * @param {*} res | |||||
| * @param {*} resolve | |||||
| * @param {*} reject | |||||
| */ | |||||
| responseMap = (res, resolve, reject) => { | |||||
| // 网络状态码200 | |||||
| if (res.statusCode == 200) { | |||||
| // 服务器code 200 成功 | |||||
| if (res.data.code == 200) { | |||||
| resolve(res.data); | |||||
| } else if (res.data.code == 1052) { | |||||
| wx.reLaunch({ | |||||
| url: '/pages/index/index' | |||||
| }) | |||||
| } else { | |||||
| reject(res.data); | |||||
| } | |||||
| } else { | |||||
| console.log("请求出错:", res); | |||||
| reject(res.data); | |||||
| } | |||||
| }; | |||||
| /** 日志 */ | |||||
| log(url, body, headers) { } | |||||
| } | |||||
| module.exports = new Request(); | |||||
| @@ -1,4 +1,4 @@ | |||||
| export const formatTime = (date: Date) => { | |||||
| export const formatTime = (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() | ||||
| @@ -13,7 +13,7 @@ export const formatTime = (date: Date) => { | |||||
| ) | ) | ||||
| } | } | ||||
| const formatNumber = (n: number) => { | |||||
| const formatNumber = (n) => { | |||||
| const s = n.toString() | const s = n.toString() | ||||
| return s[1] ? s : '0' + s | return s[1] ? s : '0' + s | ||||
| } | } | ||||
| @@ -1,15 +0,0 @@ | |||||
| { | |||||
| "name": "miniprogram-ts-less-quickstart", | |||||
| "version": "1.0.0", | |||||
| "description": "", | |||||
| "scripts": { | |||||
| }, | |||||
| "keywords": [], | |||||
| "author": "", | |||||
| "license": "", | |||||
| "dependencies": { | |||||
| }, | |||||
| "devDependencies": { | |||||
| "miniprogram-api-typings": "^2.8.3-1" | |||||
| } | |||||
| } | |||||
| @@ -2,7 +2,8 @@ | |||||
| "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", | "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", | ||||
| "projectname": "GPT-Agent", | "projectname": "GPT-Agent", | ||||
| "setting": { | "setting": { | ||||
| "compileHotReLoad": true | |||||
| "compileHotReLoad": true, | |||||
| "urlCheck": false | |||||
| }, | }, | ||||
| "libVersion": "2.30.4" | |||||
| "libVersion": "2.31.0" | |||||
| } | } | ||||
| @@ -1,5 +1,6 @@ | |||||
| { | { | ||||
| "compilerOptions": { | "compilerOptions": { | ||||
| "outDir": "./miniprogram/utils", | |||||
| "strictNullChecks": true, | "strictNullChecks": true, | ||||
| "noImplicitAny": true, | "noImplicitAny": true, | ||||
| "module": "CommonJS", | "module": "CommonJS", | ||||
| @@ -16,15 +17,17 @@ | |||||
| "noUnusedParameters": true, | "noUnusedParameters": true, | ||||
| "strict": true, | "strict": true, | ||||
| "strictPropertyInitialization": true, | "strictPropertyInitialization": true, | ||||
| "lib": ["ES2020"], | |||||
| "lib": [ | |||||
| "ES2020" | |||||
| ], | |||||
| "typeRoots": [ | "typeRoots": [ | ||||
| "./typings" | "./typings" | ||||
| ] | ] | ||||
| }, | }, | ||||
| "include": [ | "include": [ | ||||
| "./**/*.ts" | |||||
| "./**/*.ts", "miniprogram/app.js", "miniprogram/utils/util.js", "miniprogram/pages/logs/logs.js", "miniprogram/pages/index/index.js", | |||||
| ], | ], | ||||
| "exclude": [ | "exclude": [ | ||||
| "node_modules" | "node_modules" | ||||
| ] | ] | ||||
| } | |||||
| } | |||||
| @@ -0,0 +1,53 @@ | |||||
| # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | |||||
| # yarn lockfile v1 | |||||
| axios-miniprogram-adapter@^0.3.5: | |||||
| version "0.3.5" | |||||
| resolved "https://registry.yarnpkg.com/axios-miniprogram-adapter/-/axios-miniprogram-adapter-0.3.5.tgz#b02fbf61ec8899703c24eaa75fecd384509cacbd" | |||||
| integrity sha512-ZAudH+aTi0QPIy8IQm26F0nxKoTFa/mNhDfxGkG5ndsQe4RVnyyb6f50tIT13nHtNepAjZo9i+UGmTbke5+lbQ== | |||||
| dependencies: | |||||
| axios "^0.19.2" | |||||
| axios@0.26.0: | |||||
| version "0.26.0" | |||||
| resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.0.tgz#9a318f1c69ec108f8cd5f3c3d390366635e13928" | |||||
| integrity sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og== | |||||
| dependencies: | |||||
| follow-redirects "^1.14.8" | |||||
| axios@^0.19.2: | |||||
| version "0.19.2" | |||||
| resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27" | |||||
| integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA== | |||||
| dependencies: | |||||
| follow-redirects "1.5.10" | |||||
| debug@=3.1.0: | |||||
| version "3.1.0" | |||||
| resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" | |||||
| integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g== | |||||
| dependencies: | |||||
| ms "2.0.0" | |||||
| follow-redirects@1.5.10: | |||||
| version "1.5.10" | |||||
| resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a" | |||||
| integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ== | |||||
| dependencies: | |||||
| debug "=3.1.0" | |||||
| follow-redirects@^1.14.8: | |||||
| version "1.15.2" | |||||
| resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" | |||||
| integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== | |||||
| miniprogram-api-typings@^2.8.3-1: | |||||
| version "2.12.0" | |||||
| resolved "https://registry.yarnpkg.com/miniprogram-api-typings/-/miniprogram-api-typings-2.12.0.tgz#7a29c90f3e5efa36588422d1f01e22d3394aaaa1" | |||||
| integrity sha512-ibvbqeslVFur0IAvTxLMvsbtvVcMo6gwvOnj0YZHV7aeDLu091VQRrETT2QuiG9P6aZWRcxeNGJChRKVPCp9VQ== | |||||
| ms@2.0.0: | |||||
| version "2.0.0" | |||||
| resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" | |||||
| integrity sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A== | |||||