lex-xin преди 7 месеца
родител
ревизия
4ae85fc6fd

+ 22 - 0
miniprogram/api/login.ts

@@ -0,0 +1,22 @@
+import request from "../plugins/request";
+
+/** 登录或注册 */
+export const api_login = (params: any) => {
+  return request({
+    url: `/edu-app/userlogin`,
+    noToken: true,
+    method: "POST",
+    data: params,
+  } as any);
+};
+
+/** 获取用户信息 */
+export const api_queryUserInfo = (params: any) => {
+  return request({
+    url: `/edu-app/user/getUserInfo`,
+    method: "get",
+    data: params,
+  } as any);
+};
+
+

+ 2 - 1
miniprogram/app.json

@@ -3,7 +3,8 @@
     "pages/index/index",
     "pages/logs/logs",
     "pages/orders/orders",
-    "pages/login/login"
+    "pages/login/login",
+    "pages/orders/order-detail"
   ],
   "window": {
     "navigationBarTextStyle": "black",

+ 63 - 1
miniprogram/app.ts

@@ -1,15 +1,77 @@
 // app.ts
-// app.ts
+import { api_login, api_queryUserInfo } from './api/login';
 const config = require("./config");
 
 App<IAppOption>({
   globalData: {
     baseUrl: config?.baseUrl,
+    appId: '',
+    deviceNum: '', // 设备信息
+    isLogin: false, // 是否登录
+    userInfo: {} as any
   },
   onLaunch() {
     // 展示本地存储能力
     // const logs = wx.getStorageSync('logs') || []
     // logs.unshift(Date.now())
     // wx.setStorageSync('logs', logs)
+    this.setAppId();
+
+    // 登录
+    wx.login({
+      success: async (res) => {
+        this.onLogin(res.code)
+      },
+    })
   },
+  setAppId() {
+    //获取当前小程序appId
+    const accountInfo = wx.getAccountInfoSync();
+    this.globalData.appId = accountInfo.miniProgram.appId;
+    // wxRequest.config.appid = accountInfo.miniProgram.appId;
+    //先设置appid再引入接口文件,防止appid未更新问题
+    // require("./utils/request/api.js");
+    // 获取设备信息
+    const deviceInfo = wx.getDeviceInfo()
+      // 品牌 设备型号 操作系统及版本 客户端平台
+    const deviceNum = deviceInfo.brand + '-' + deviceInfo.model + '-' + deviceInfo.platform + '-' + deviceInfo.system
+    this.globalData.deviceNum = deviceNum
+  },
+  // userInfoReadyCallback(result) {
+  //   console.log(result, 'result')
+  // }
+  /** 微信登录 */
+  async onLogin(code: string) {
+    try {
+      // 开始登录
+      const { data } = await api_login({
+        autoRegister: false,
+        client_id: 'cooleshow-student-wxlite',
+        client_secret: 'cooleshow-student-wxlite',
+        deviceNum: this.globalData.deviceNum,
+        extra: '',
+        grant_type: 'password',
+        loginType: 'WECHAT_MA',
+        multiUser: false,
+        username: this.globalData.appId,
+        password: code
+      })
+
+      if(data.code === 200) {
+        const userToken = data.data.authentication.token_type + " " + data.data.authentication.access_token;
+        wx.setStorageSync("token", userToken);
+        this.globalData.isLogin = true;
+        const users = await api_queryUserInfo({ wxAppId: this.globalData.appId })
+        if(users.data.code === 200) {
+          this.globalData.userInfo = users.data.data
+        } else {
+          wx.removeStorageSync("token");
+          this.globalData.isLogin = false
+        }
+        console.log(users)
+      } else {
+        this.globalData.isLogin = false;
+      }
+    } catch {}
+  }
 })

+ 5 - 6
miniprogram/config.ts

@@ -1,11 +1,10 @@
-const environmentVariable = "test";
+const environmentVariable = "dev";
 const apiUrlInfo = {
-  dev: "https://dev.colexiu.com",
-  test: "https://test.colexiu.com",
-  ponline: "https://ponline.colexiu.com",
-  online: "https://online.colexiu.com",
+  dev: "https://dev.kt.colexiu.com",
+  test: "https://test.kt.colexiu.com",
+  online: "https://online.kt.colexiu.com",
 };
 const baseUrl = apiUrlInfo[environmentVariable];
 module.exports = {
-  baseUrl,
+  baseUrl
 };

+ 12 - 1
miniprogram/pages/index/index.less

@@ -178,7 +178,18 @@ page {
     image {
       display: block;
       width: 100%;
-      height: 1441.5rpx;
+    }
+    .img1 {
+      height: 1128rpx;
+    }
+    .img2 {
+      height: 1810rpx
+    }
+    .img3 {
+      height: 1336rpx;
+    }
+    .img4 {
+      height: 1750rpx;
     }
   }
 }

+ 30 - 3
miniprogram/pages/index/index.ts

@@ -19,16 +19,31 @@ Component({
         })
       }
     },
+    isLogin() {
+      // 判断是否登录
+      if(!app.globalData.isLogin) {
+        wx.navigateTo({
+          url: '../login/login',
+        })
+        return false
+      }
+      return true
+    },
     /** 我的订单 */
     onOrder() {
+      // 判断是否登录
+      if(!this.isLogin()) {
+        return
+      }
       wx.navigateTo({
         url: '../orders/orders',
       })
     },
     onBuyShop() {
-      // wx.navigateTo({
-      //   url: '../login/login',
-      // })
+      // 判断是否登录
+      if(!this.isLogin()) {
+        return
+      }
       this.setData({
         popupShow: true
       })
@@ -37,6 +52,18 @@ Component({
       this.setData({
         popupShow: false
       })
+    },
+    onSubmit() {
+      // 判断是否登录
+      if(!this.isLogin()) {
+        return
+      }
+      wx.navigateTo({
+        url: '../orders/order-detail',
+      })
+      this.setData({
+        popupShow: false
+      })
     }
     // getUserProfile() {
     //   // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗

+ 5 - 5
miniprogram/pages/index/index.wxml

@@ -64,10 +64,10 @@
       <view class="goodsIntro">
         <view class="title">图文详情</view>
         <view class="images">
-          <image src="https://oss.dayaedu.com/ktyq/1731664304424.png"></image>
-          <image src="https://oss.dayaedu.com/ktyq/1731664318588.png"></image>
-          <image src="https://oss.dayaedu.com/ktyq/1731664330981.png"></image>
-          <image src="https://oss.dayaedu.com/ktyq/1731664343706.png"></image>
+          <image class="img1" src="https://oss.dayaedu.com/ktyq/1731664304424.png"></image>
+          <image class="img2" src="https://oss.dayaedu.com/ktyq/1731664318588.png"></image>
+          <image class="img3" src="https://oss.dayaedu.com/ktyq/1731664330981.png"></image>
+          <image class="img4" src="https://oss.dayaedu.com/ktyq/1731664343706.png"></image>
         </view>
       </view>
     </view>
@@ -110,7 +110,7 @@
           </view>
         </view>
 
-        <button type="primary">立即购买</button>
+        <button type="primary" bind:tap="onSubmit">立即购买</button>
       </view>
     </view>
   </view>

+ 5 - 0
miniprogram/pages/login/login.less

@@ -34,6 +34,11 @@
     color: #FFFFFF;
     padding-top: 0;
     padding-bottom: 0;
+    &[disabled][type=primary] {
+      color: #fff;
+      background: linear-gradient( 270deg, #FF204B 0%, #FE5B71 100%);
+      opacity: 0.8;
+    }
   }
 
   .protocol-section {

+ 75 - 30
miniprogram/pages/login/login.ts

@@ -1,53 +1,98 @@
+import { api_login, api_queryUserInfo } from "../../api/login"
+
 // pages/login/login.ts
+const app = getApp<IAppOption>()
 Page({
-
   /**
    * 页面的初始数据
    */
   data: {
-    code: '',
     isAgree: false,
   },
-  
   /**
    * 生命周期函数--监听页面加载
    */
-  onLoad() {
-    // 登录
+  onLoad() {},
+  getLogin(e: any) {
+    console.log(e, 'any')
+    const { detail } = e
+    // if(!this.data.isAgree) {
+    //   wx.showToast({
+    //     title: '请先阅读并勾选协议',
+    //     icon: 'none'
+    //   })
+    //   return
+    // }
     wx.login({
-      success: res => {
-        // 发送 res.code 到后台换取 openId, sessionKey, unionId
-        this.setData({
-          code: res.code
-        })
-      },
-    })
-  },
-  onLogin() {
-    if(!this.data.isAgree) {
-      wx.showToast({
-        title: '请先阅读并勾选协议',
-        icon: 'none'
-      })
-      return
-    }
-    // 登录
-    wx.getUserProfile({
-      desc: '获取用户信息',
       success: (res) => {
-        console.log(res, 'res')
-        
-      },
-      fail: (res) => {
-        console.log(res, 'res')
+        const params = {
+          code: res.code,
+          iv: detail.iv,
+          encryptedData: detail.encryptedData
+        }
+        this.onLoginSync(params)
       }
     })
   },
-  onAgree(e: any) {
+  onAgree() {
     this.setData({
       isAgree: !this.data.isAgree
     })
   },
+   /** 微信登录 */
+   async onLoginSync(params: { code: string, iv: string, encryptedData: string }) {
+    try {
+      // 开始登录
+      console.log({
+        autoRegister: false,
+        client_id: 'cooleshow-student-wxlite',
+        client_secret: 'cooleshow-student-wxlite',
+        deviceNum: app.globalData.deviceNum,
+        extra: JSON.stringify({
+          iv: params.iv,
+          encryptedData: params.encryptedData
+        }),
+        grant_type: 'password',
+        loginType: 'WECHAT_MA',
+        multiUser: false,
+        username: app.globalData.appId,
+        password: params.code
+      })
+      const { data } = await api_login({
+        autoRegister: false,
+        client_id: 'cooleshow-student-wxlite',
+        client_secret: 'cooleshow-student-wxlite',
+        deviceNum: app.globalData.deviceNum,
+        extra: JSON.stringify({
+          iv: params.iv,
+          encryptedData: params.encryptedData
+        }),
+        grant_type: 'password',
+        loginType: 'WECHAT_MA',
+        multiUser: false,
+        username: app.globalData.appId,
+        password: params.code
+      })
+
+      if(data.code === 200) {
+        const userToken = data.data.authentication.token_type + " " + data.data.authentication.access_token;
+        wx.setStorageSync("token", userToken);
+        app.globalData.isLogin = true;
+        const users = await api_queryUserInfo({ wxAppId: app.globalData.appId })
+        if(users.data.code === 200) {
+          app.globalData.userInfo = users.data.data
+        } else {
+          wx.removeStorageSync("token");
+          app.globalData.isLogin = false
+        }
+        console.log(users)
+      } else {
+        app.globalData.isLogin = false;
+      }
+    } catch {
+      console.log('error')
+    }
+  },
   /**
    * 生命周期函数--监听页面初次渲染完成
    */

+ 1 - 1
miniprogram/pages/login/login.wxml

@@ -7,7 +7,7 @@
   </view>
   <view class="login-section">
     <view class="btnSection">
-      <button type="primary" open-type="getPhoneNumber" bindgetphonenumber="getLogin">微信一键登录</button>
+      <button type="primary" disabled="{{ !isAgree }}" open-type="getPhoneNumber" bindgetphonenumber="getLogin">微信一键登录</button>
     </view>
     <view class="protocol-section">
       <image wx:if="{{isAgree}}" bind:tap="onAgree" src="./images/radio-active.png" class="radio"></image>

BIN
miniprogram/pages/orders/images/error.png


BIN
miniprogram/pages/orders/images/ing.png


BIN
miniprogram/pages/orders/images/success.png


BIN
miniprogram/pages/orders/images/wait.png


+ 5 - 0
miniprogram/pages/orders/order-detail.json

@@ -0,0 +1,5 @@
+{
+  "usingComponents": {
+    "navigation-bar": "/components/navigation-bar/navigation-bar"
+  }
+}

+ 175 - 0
miniprogram/pages/orders/order-detail.less

@@ -0,0 +1,175 @@
+/* pages/orders/order-detail.wxss */
+page {
+  height: 100vh;
+  display: flex;
+  flex-direction: column;
+  background: #F5F6F7;
+}
+
+.order-status {
+  margin: 24rpx 26rpx 0;
+  background-color: #FFFFFF;
+  border-radius: 20rpx;
+  padding: 24rpx 32rpx;
+  .status {
+    display: flex;
+    padding-bottom: 24rpx;
+    image {
+      width: 48rpx;
+      height: 48rpx;
+      margin-right: 16rpx;
+    }
+    text {
+      font-weight: 600;
+      font-size: 36rpx;
+      color: #131415;
+      line-height: 48rpx;
+    }
+  }
+  .tips {
+    font-size: 28rpx;
+    color: #777777;
+    line-height: 40rpx;
+  }
+}
+
+.item-content {
+  margin: 24rpx 26rpx 0;
+  border-radius: 20rpx;
+  padding: 28rpx 24rpx;
+  display: flex;
+  background-color: #FFFFFF;
+
+  .goods-icon {
+    width: 160rpx;
+    height: 160rpx;
+    margin-right: 24rpx;
+    flex-shrink: 0;
+  }
+
+  .goods-desc {
+    flex: 1 auto;
+    display: flex;
+    flex-direction: column;
+  }
+
+  .goodsInfo {
+    display: flex;
+    justify-content: space-between;
+    padding-top: 4rpx;
+    .goods-name {
+      flex: 1 auto;
+      white-space: nowrap;
+      overflow: hidden;
+      font-weight: 600;
+      font-size: 28rpx;
+      text-overflow: ellipsis;
+      max-width: 310rpx;
+    }
+    .goods-price {
+      flex-shrink: 0;
+      font-family: DINAlternate, DINAlternate;
+      font-weight: bold;
+      font-size: 28rpx;
+      color: #131415;
+      line-height: 48rpx;
+    }
+  }
+
+  .goods-type {
+    display: flex;
+    justify-content: space-between;
+    padding-top: 12rpx;
+    .goods-card {
+      height: 40rpx;
+      background: #FEEDF0;
+      border-radius: 6rpx;
+      font-size: 26rpx;
+      color: #FE2451;
+      line-height: 36rpx;
+      padding: 0 12rpx;
+    }
+    .goods-num {
+      font-size: 28rpx;
+      color: #777777;
+      line-height: 36rpx;
+    }
+  }
+
+}
+
+.order-time {
+  margin: 24rpx 26rpx 0;
+  border-radius: 20rpx;
+  padding: 36rpx 24rpx;
+  background-color: #FFFFFF;
+
+  .order-item {
+    display: flex;
+    justify-content: space-between;
+    padding-bottom: 36rpx;
+    &:last-child {
+      padding-bottom: 0;
+    }
+    .title {
+      font-size: 28rpx;
+      color: #131415;
+      line-height: 40rpx;
+    }
+    .value {
+      font-size: 28rpx;
+      color: #777777;
+      line-height: 40rpx;
+    }
+  }
+}
+
+.order-btn {
+  position: fixed;
+  bottom: 0;
+  left: 0;
+  width: 100%;
+  background-color: #FFFFFF;
+  padding: 20rpx 32rpx 58rpx 40rpx;
+  display: flex;
+  justify-content: space-between;
+  box-sizing: border-box;
+
+  .price {
+    display: flex;
+    align-items: center;
+
+    .desc {
+      font-weight: 500;
+      font-size: 28rpx;
+      color: #131415;
+      line-height: 40rpx;
+    }
+    .currentPrice {
+      font-weight: bold;
+      color: #FE2451;
+      font-family: DINAlternate, DINAlternate;
+      .stuff {
+        font-size: 32rpx;
+      }
+      .priceZ {
+        font-size: 56rpx;
+      }
+      .priceF {
+        font-size: 32rpx;
+      }
+    }
+  }
+
+  button {
+    margin: 0;
+    width: auto;
+    background: linear-gradient( 270deg, #FF204B 0%, #FE5B71 100%);
+    border-radius: 78rpx;
+    padding: 22rpx 84rpx;
+    font-weight: 500;
+    font-size: 32rpx;
+    color: #FFFFFF;
+    line-height: 44rpx;
+  }
+}

+ 66 - 0
miniprogram/pages/orders/order-detail.ts

@@ -0,0 +1,66 @@
+// pages/orders/order-detail.ts
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload() {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh() {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom() {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage() {
+
+  }
+})

+ 52 - 0
miniprogram/pages/orders/order-detail.wxml

@@ -0,0 +1,52 @@
+<!--pages/orders/order-detail.wxml-->
+<view class="container">
+  <navigation-bar title="订单详情"></navigation-bar>
+
+  <scroll-view class="record-list" type="list" scroll-y bindscrolltolower="loadMore">
+    <view class="order-status">
+      <view class="status">
+        <image src="./images/ing.png"></image>
+        <text>等待付款</text>
+      </view>
+      <view class="tips">请尽快完成支付,以便我们为您处理订单</view>
+    </view>
+
+    <view class="item-content">
+      <image class='goods-icon' src="https://oss.dayaedu.com/ktyq/1731664204915.png" mode="" />
+      <view class="goods-desc">
+        <view class="goodsInfo">
+          <view class="goods-name">音乐数字课堂AI学练工堂AI学练工音乐数字课堂AI学练工堂AI学练工</view>
+          <view class="goods-price">¥ 600.00</view>
+        </view>
+        <view class="goods-type">
+          <view class="goods-card">一年卡</view>
+          <view class="goods-num">x1</view>
+        </view>
+      </view>
+    </view>
+
+    <view class="order-time">
+      <view class="order-item">
+        <view class="title">订单号</view>
+        <view class="value">2133442226668</view>
+      </view>
+      <view class="order-item">
+        <view class="title">下单时间</view>
+        <view class="value">2023-07-12 18:12:45</view>
+      </view>
+    </view>
+  </scroll-view>
+
+  <view class="order-btn">
+    <view class="price">
+      <view class="desc">订单金额:</view>
+      <view class="currentPrice">
+        <text class="stuff">¥</text>
+        <text class="priceZ">356</text>
+        <text class="priceF">.00</text>
+      </view>
+    </view>
+
+    <button type="primary">继续支付</button>
+  </view>
+</view>

+ 3 - 3
miniprogram/plugins/request.ts

@@ -22,8 +22,8 @@ module.exports = function (options: any) {
     } else {
       requestType = "application/json; charset=UTF-8";
     }
-    // tocken
-    const Authorization = wx.getStorageSync("tocken");
+    // token
+    const Authorization = wx.getStorageSync("token");
     // open 接口不需要传token
     const isOpenApi = options.url.includes('/open/')
     const isCodeApi = options.url.includes('/code/')
@@ -59,7 +59,7 @@ module.exports = function (options: any) {
           }
           reject(res.data.msg);
         } else if (res.data.code == 403) {
-          wx.setStorageSync("tocken", "");
+          wx.setStorageSync("token", "");
           if(!hideLoading) {
             setTimeout(() => {
               wx.showToast({

+ 6 - 1
typings/index.d.ts

@@ -3,7 +3,12 @@
 interface IAppOption {
   globalData: {
     userInfo?: WechatMiniprogram.UserInfo,
-    baseUrl: string
+    baseUrl: string,
+    appId: string,
+    deviceNum: string,
+    isLogin: boolean,
   }
   userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback,
+  setAppId(): void,
+  onLogin(code: string): void
 }