Commit ea23f1e7 authored by haiyoucuv's avatar haiyoucuv

init

parent 79085a3a
// app.ts // app.ts
import { dbLogin, request } from "./utils/request";
App<IAppOption>({ App<IAppOption>({
globalData: {}, globalData: {},
onLaunch() { onLaunch() {
// 展示本地存储能力 // 展示本地存储能力
const logs = wx.getStorageSync('logs') || [] const logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now()) logs.unshift(Date.now())
wx.setStorageSync('logs', logs) wx.setStorageSync('logs', logs)
// 登录 // 登录
wx.login({ wx.login({
success: res => { success: async (res) => {
console.log(res.code) console.log(res.code)
// 发送 res.code 到后台换取 openId, sessionKey, unionId // 发送 res.code 到后台换取 openId, sessionKey, unionId
}, await dbLogin({code: res.code});
}) },
}, })
},
}) })
\ No newline at end of file
...@@ -149,6 +149,17 @@ ...@@ -149,6 +149,17 @@
} }
} }
.getPhoneBtn{
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
width: 100vw !important;
height: 100vh;
opacity: 0;
}
// .userinfo { // .userinfo {
// display: flex; // display: flex;
......
...@@ -15,6 +15,7 @@ ComponentWithStore({ ...@@ -15,6 +15,7 @@ ComponentWithStore({
actions: {}, actions: {},
}, },
data: { data: {
showPhoneBtn: true,
showGetPanel: false, showGetPanel: false,
showAlGetPanel: false, showAlGetPanel: false,
userInfo: { userInfo: {
...@@ -25,7 +26,9 @@ ComponentWithStore({ ...@@ -25,7 +26,9 @@ ComponentWithStore({
canIUseGetUserProfile: wx.canIUse('getUserProfile'), canIUseGetUserProfile: wx.canIUse('getUserProfile'),
canIUseNicknameComp: wx.canIUse('input.type.nickname'), canIUseNicknameComp: wx.canIUse('input.type.nickname'),
}, },
ready() {
store.updateHomeInfo();
},
methods: { methods: {
getPhoneNumber(e: any) { getPhoneNumber(e: any) {
console.log(e.detail) console.log(e.detail)
...@@ -48,9 +51,6 @@ ComponentWithStore({ ...@@ -48,9 +51,6 @@ ComponentWithStore({
url: '../logs/logs', url: '../logs/logs',
}) })
}, },
changeStore() {
store.updateHomeInfo();
},
onChooseAvatar(e: any) { onChooseAvatar(e: any) {
const {avatarUrl} = e.detail const {avatarUrl} = e.detail
const {nickName} = this.data.userInfo const {nickName} = this.data.userInfo
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
</swiper-item> </swiper-item>
</swiper> </swiper>
<view class="user_info"> <view class="user_info">
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">测试手机号</button>
<view class="avatar_box"> <view class="avatar_box">
<image class="avatar" src="{{userInfo.avatarUrl}}"></image> <image class="avatar" src="{{userInfo.avatarUrl}}"></image>
</view> </view>
...@@ -49,4 +48,13 @@ ...@@ -49,4 +48,13 @@
</view> --> </view> -->
<get-panel wx:if="{{showGetPanel}}" bind:close="closeGetPanel" /> <get-panel wx:if="{{showGetPanel}}" bind:close="closeGetPanel" />
<al-get-panel wx:if="{{showAlGetPanel}}" bind:close="closeAlGetPanel" /> <al-get-panel wx:if="{{showAlGetPanel}}" bind:close="closeAlGetPanel" />
</view> </view>
\ No newline at end of file
<!--获取手机号按钮-->
<button
type="primary"
wx:if="{{showPhoneBtn}}"
class="getPhoneBtn"
open-type="getPhoneNumber"
bindgetphonenumber="getPhoneNumber"
></button>
import { makeAutoObservable } from 'mobx-miniprogram' import { makeAutoObservable } from 'mobx-miniprogram'
import { request } from "../utils/request";
import { API_PATH } from "../utils/config";
class Store { class Store {
...@@ -19,16 +21,13 @@ class Store { ...@@ -19,16 +21,13 @@ class Store {
] ]
} }
updateHomeInfo() { async updateHomeInfo() {
this.homeInfo = {
name: '张三', const res = await request({
age: 18, url: API_PATH.index,
banner: [ });
"https://yun.duiba.com.cn/polaris/banner.bf4a3033e8bb2cb9eb20c534d002879a2f6b5579.png", console.log(res)
"//yun.duiba.com.cn/polaris/%E5%96%9D%E9%B2%9C%E5%A5%B6.5815326bdfc25045c0a8ee71beb10c13b0147acd.png",
"//yun.duiba.com.cn/polaris/%E9%B2%9C%E7%89%9B%E5%A5%B6.fd352be87520d04261ba36348022c36836e4c819.png"
]
}
} }
} }
......
// 【开发环境】 // 【开发环境】
export const devOptions = { export const devOptions = {
BASE_URL: 'https://activity.m.duibadev.com.cn/', BASE_URL: 'https://activity.m.duibadev.com.cn',
appKey: 'jlg88lyxz7siqtmr', appKey: 'jlg88lyxz7siqtmr',
} }
// 【测试环境】 // 【测试环境】
export const testOptions = { export const testOptions = {
BASE_URL: 'https://activity.m.duibatest.com.cn/', BASE_URL: 'https://activity.m.duibatest.com.cn',
appKey: '3tWCs93A2ZfuvMyJkWxC7xddg6qA', appKey: '3tWCs93A2ZfuvMyJkWxC7xddg6qA',
projectId: "test", projectId: "test",
} }
// 【预发环境】 // 【预发环境】
export const prevOptions = { export const prevOptions = {
BASE_URL: 'https://activity-pre.m.duiba.com.cn/', // 免登接口有预发的环境 BASE_URL: 'https://activity-pre.m.duiba.com.cn', // 免登接口有预发的环境
appKey: '388ENcX8CGJBEdn2hyZA5zDkqpR6', appKey: '388ENcX8CGJBEdn2hyZA5zDkqpR6',
projectId: "prev", projectId: "prev",
} }
// 【线上环境】 // 【线上环境】
export const publishOptions = { export const publishOptions = {
BASE_URL: 'https://activity.m.duiba.com.cn/', BASE_URL: 'https://activity.m.duiba.com.cn',
appKey: '388ENcX8CGJBEdn2hyZA5zDkqpR6', appKey: '388ENcX8CGJBEdn2hyZA5zDkqpR6',
projectId: "publish", projectId: "publish",
} }
...@@ -29,8 +29,8 @@ export default publishOptions; ...@@ -29,8 +29,8 @@ export default publishOptions;
export enum API_PATH { export enum API_PATH {
index = "/home/coop_index.do", index = "home/coop_index.do",
activity = "/home/coop_activity.do", activity = "home/coop_activity.do",
subscribe = "home/coop_subscribe.do",
login = "/wechat/jlb/login", login = "/wechat/jlb/login",
subscribe = "/home/coop_subscribe.do",
} }
\ No newline at end of file
import env from './config'; import env, { API_PATH } from './config';
const headersConfig = { const headersConfig = {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
...@@ -13,39 +13,86 @@ interface IReqConfig { ...@@ -13,39 +13,86 @@ interface IReqConfig {
method?: IReqMethod; method?: IReqMethod;
} }
interface IResData {
success: boolean;
data?: { [key in string]: any };
code?: string;
message?: string;
}
let loginToken: string = ""; let loginToken: string = "";
export const request = (config: IReqConfig) => new Promise((resolve, reject) => { export function request(config: IReqConfig) {
const {BASE_URL, projectId} = env; return new Promise<IResData>((resolve, reject) => {
const {BASE_URL, projectId} = env;
const {url, headers, data, method = "GET"} = config; let {url, headers, data, method = "GET"} = config;
const type = (method.toUpperCase() as IReqMethod) || 'GET'; method = (method.toUpperCase() as IReqMethod) || 'GET';
const header = { const header = {
...headersConfig, ...headersConfig,
...headers, ...headers,
loginToken, loginToken,
}; };
const params = {
...data,
};
const params = { if (url.indexOf("/") != 0) {
...data, url = `/${projectId}/${url}`;
}
wx.request({
method,
url: `${BASE_URL}${url}?_t=${Date.now()}`,
data: params,
header,
success(response) {
console.log(1111, response)
if (+response.statusCode === 200) {
resolve(response.data as IResData);
} else {
resolve({success: false});
// reject(new Error(`请求失败 statusCode: ${response.statusCode}`));
}
},
fail(error) {
resolve({success: false});
// reject(new Error(error.errMsg));
},
})
})
}
export async function dbLogin(
param: {
code?, encryptedData?, iv?, nickname?, avatar?
}
) {
const {code, encryptedData = null, iv, nickname, avatar} = param;
const params: any = {
appKey: env.appKey,
}; };
wx.request({ code && (params.code = code);
method: type, encryptedData && (encryptedData.code = encryptedData);
url: `${BASE_URL}${projectId}${url}`, iv && (iv.code = iv);
nickname && (nickname.code = nickname);
avatar && (avatar.code = avatar);
const {success, data} = await request({
url: API_PATH.login,
data: params, data: params,
header, });
success(response) {
if (+response.statusCode === 200) { if (!success) {
resolve(response.data); return;
} else { }
reject(new Error(`请求失败 statusCode: ${response.statusCode}`));
} loginToken = data.loginToken;
}, }
fail(error) { \ No newline at end of file
reject(new Error(error.errMsg));
},
})
})
\ No newline at end of file
{
"data": {
"success": true,
"message": "true",
"code": "0",
"data": {
"topBanners": [
"https://yun.duiba.com.cn/polaris/%E5%9B%BE%E5%B1%82%20541.3c7ff6d4bed9f88be00c52551b05b54d94d1fd95.png",
"//yun.duiba.com.cn/polaris/%E5%96%9D%E9%B2%9C%E5%A5%B6.5815326bdfc25045c0a8ee71beb10c13b0147acd.png",
"//yun.duiba.com.cn/polaris/%E9%B2%9C%E7%89%9B%E5%A5%B6.fd352be87520d04261ba36348022c36836e4c819.png"
],
"productList": [
{
"name": "商品1",
"img": "//yun.duiba.com.cn/polaris/%E5%96%9D%E9%B2%9C%E5%A5%B6.5815326bdfc25045c0a8ee71beb10c13b0147acd.png",
"content": "商品1的内容"
},
{
"name": "商品1",
"img": "//yun.duiba.com.cn/polaris/%E9%B2%9C%E7%89%9B%E5%A5%B6.fd352be87520d04261ba36348022c36836e4c819.png",
"content": "商品1的内容"
}
]
}
},
"statusCode": 200,
"header": ""
}
\ No newline at end of file
{
"data": {
"success": true,
"message": "true",
"code": "0",
"data": {
"nickname": 1231231,
"avatar": 1231231,
"mobile": 17606542514,
"subscribe": false,
"first": false,
"topBanners": [
"https://yun.duiba.com.cn/polaris/%E5%9B%BE%E5%B1%82%20541.3c7ff6d4bed9f88be00c52551b05b54d94d1fd95.png",
"//yun.duiba.com.cn/polaris/%E5%96%9D%E9%B2%9C%E5%A5%B6.5815326bdfc25045c0a8ee71beb10c13b0147acd.png",
"//yun.duiba.com.cn/polaris/%E9%B2%9C%E7%89%9B%E5%A5%B6.fd352be87520d04261ba36348022c36836e4c819.png"
],
"activities": [
"111111111"
]
}
},
"statusCode": 200,
"header": ""
}
\ No newline at end of file
{
"data": {
"success": true,
"message": "true",
"code": "0",
"desc": "desc",
"timestamp": 1719284416812,
"data": {
"loginToken": "loginToken",
"sessionId": "sessionId"
}
},
"statusCode": 200,
"header": ""
}
\ No newline at end of file
{
"data": {
"success": true,
"message": "true",
"code": "0",
"data": true
},
"statusCode": 200,
"header": ""
}
\ No newline at end of file
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
"projectname": "junlebao-milk-20240619", "projectname": "junlebao-milk-20240619",
"setting": { "setting": {
"compileHotReLoad": true, "compileHotReLoad": true,
"preloadBackgroundData": false "preloadBackgroundData": false,
"urlCheck": false
}, },
"libVersion": "3.4.6" "libVersion": "3.4.6"
} }
\ No newline at end of file
{ {
"compilerOptions": { "compilerOptions": {
"strictNullChecks": true, "strictNullChecks": false,
"noImplicitAny": true, "noImplicitAny": false,
"module": "CommonJS", "module": "CommonJS",
"target": "ES2020", "target": "ES2020",
"allowJs": true, "allowJs": true,
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
"noImplicitReturns": true, "noImplicitReturns": true,
"alwaysStrict": true, "alwaysStrict": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"noUnusedLocals": true, "noUnusedLocals": false,
"noUnusedParameters": true, "noUnusedParameters": false,
"strict": true, "strict": false,
"strictPropertyInitialization": true, "strictPropertyInitialization": true,
"lib": ["ES2020"], "lib": ["ES2020"],
"typeRoots": [ "typeRoots": [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment