Commit ea23f1e7 authored by haiyoucuv's avatar haiyoucuv

init

parent 79085a3a
// app.ts
import { dbLogin, request } from "./utils/request";
App<IAppOption>({
globalData: {},
onLaunch() {
......@@ -9,9 +11,10 @@ App<IAppOption>({
// 登录
wx.login({
success: res => {
success: async (res) => {
console.log(res.code)
// 发送 res.code 到后台换取 openId, sessionKey, unionId
await dbLogin({code: res.code});
},
})
},
......
......@@ -149,6 +149,17 @@
}
}
.getPhoneBtn{
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
width: 100vw !important;
height: 100vh;
opacity: 0;
}
// .userinfo {
// display: flex;
......
......@@ -15,6 +15,7 @@ ComponentWithStore({
actions: {},
},
data: {
showPhoneBtn: true,
showGetPanel: false,
showAlGetPanel: false,
userInfo: {
......@@ -25,7 +26,9 @@ ComponentWithStore({
canIUseGetUserProfile: wx.canIUse('getUserProfile'),
canIUseNicknameComp: wx.canIUse('input.type.nickname'),
},
ready() {
store.updateHomeInfo();
},
methods: {
getPhoneNumber(e: any) {
console.log(e.detail)
......@@ -48,9 +51,6 @@ ComponentWithStore({
url: '../logs/logs',
})
},
changeStore() {
store.updateHomeInfo();
},
onChooseAvatar(e: any) {
const {avatarUrl} = e.detail
const {nickName} = this.data.userInfo
......
......@@ -6,7 +6,6 @@
</swiper-item>
</swiper>
<view class="user_info">
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">测试手机号</button>
<view class="avatar_box">
<image class="avatar" src="{{userInfo.avatarUrl}}"></image>
</view>
......@@ -50,3 +49,12 @@
<get-panel wx:if="{{showGetPanel}}" bind:close="closeGetPanel" />
<al-get-panel wx:if="{{showAlGetPanel}}" bind:close="closeAlGetPanel" />
</view>
<!--获取手机号按钮-->
<button
type="primary"
wx:if="{{showPhoneBtn}}"
class="getPhoneBtn"
open-type="getPhoneNumber"
bindgetphonenumber="getPhoneNumber"
></button>
import { makeAutoObservable } from 'mobx-miniprogram'
import { request } from "../utils/request";
import { API_PATH } from "../utils/config";
class Store {
......@@ -19,16 +21,13 @@ class Store {
]
}
updateHomeInfo() {
this.homeInfo = {
name: '张三',
age: 18,
banner: [
"https://yun.duiba.com.cn/polaris/banner.bf4a3033e8bb2cb9eb20c534d002879a2f6b5579.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"
]
}
async updateHomeInfo() {
const res = await request({
url: API_PATH.index,
});
console.log(res)
}
}
......
// 【开发环境】
export const devOptions = {
BASE_URL: 'https://activity.m.duibadev.com.cn/',
BASE_URL: 'https://activity.m.duibadev.com.cn',
appKey: 'jlg88lyxz7siqtmr',
}
// 【测试环境】
export const testOptions = {
BASE_URL: 'https://activity.m.duibatest.com.cn/',
BASE_URL: 'https://activity.m.duibatest.com.cn',
appKey: '3tWCs93A2ZfuvMyJkWxC7xddg6qA',
projectId: "test",
}
// 【预发环境】
export const prevOptions = {
BASE_URL: 'https://activity-pre.m.duiba.com.cn/', // 免登接口有预发的环境
BASE_URL: 'https://activity-pre.m.duiba.com.cn', // 免登接口有预发的环境
appKey: '388ENcX8CGJBEdn2hyZA5zDkqpR6',
projectId: "prev",
}
// 【线上环境】
export const publishOptions = {
BASE_URL: 'https://activity.m.duiba.com.cn/',
BASE_URL: 'https://activity.m.duiba.com.cn',
appKey: '388ENcX8CGJBEdn2hyZA5zDkqpR6',
projectId: "publish",
}
......@@ -29,8 +29,8 @@ export default publishOptions;
export enum API_PATH {
index = "/home/coop_index.do",
activity = "/home/coop_activity.do",
index = "home/coop_index.do",
activity = "home/coop_activity.do",
subscribe = "home/coop_subscribe.do",
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 = {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
......@@ -13,14 +13,22 @@ interface IReqConfig {
method?: IReqMethod;
}
interface IResData {
success: boolean;
data?: { [key in string]: any };
code?: string;
message?: string;
}
let loginToken: string = "";
export const request = (config: IReqConfig) => new Promise((resolve, reject) => {
export function request(config: IReqConfig) {
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 = {
...headersConfig,
......@@ -32,20 +40,59 @@ export const request = (config: IReqConfig) => new Promise((resolve, reject) =>
...data,
};
if (url.indexOf("/") != 0) {
url = `/${projectId}/${url}`;
}
wx.request({
method: type,
url: `${BASE_URL}${projectId}${url}`,
method,
url: `${BASE_URL}${url}?_t=${Date.now()}`,
data: params,
header,
success(response) {
console.log(1111, response)
if (+response.statusCode === 200) {
resolve(response.data);
resolve(response.data as IResData);
} else {
reject(new Error(`请求失败 statusCode: ${response.statusCode}`));
resolve({success: false});
// reject(new Error(`请求失败 statusCode: ${response.statusCode}`));
}
},
fail(error) {
reject(new Error(error.errMsg));
resolve({success: false});
// reject(new Error(error.errMsg));
},
})
})
\ No newline at end of file
})
}
export async function dbLogin(
param: {
code?, encryptedData?, iv?, nickname?, avatar?
}
) {
const {code, encryptedData = null, iv, nickname, avatar} = param;
const params: any = {
appKey: env.appKey,
};
code && (params.code = code);
encryptedData && (encryptedData.code = encryptedData);
iv && (iv.code = iv);
nickname && (nickname.code = nickname);
avatar && (avatar.code = avatar);
const {success, data} = await request({
url: API_PATH.login,
data: params,
});
if (!success) {
return;
}
loginToken = data.loginToken;
}
\ 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 @@
"projectname": "junlebao-milk-20240619",
"setting": {
"compileHotReLoad": true,
"preloadBackgroundData": false
"preloadBackgroundData": false,
"urlCheck": false
},
"libVersion": "3.4.6"
}
\ No newline at end of file
{
"compilerOptions": {
"strictNullChecks": true,
"noImplicitAny": true,
"strictNullChecks": false,
"noImplicitAny": false,
"module": "CommonJS",
"target": "ES2020",
"allowJs": true,
......@@ -12,9 +12,9 @@
"noImplicitReturns": true,
"alwaysStrict": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strict": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"strict": false,
"strictPropertyInitialization": true,
"lib": ["ES2020"],
"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