diff --git a/miniprogram/app.less b/miniprogram/app.less index fe7b8d4..b4a8591 100644 --- a/miniprogram/app.less +++ b/miniprogram/app.less @@ -13,6 +13,34 @@ -moz-osx-font-smoothing: grayscale; } +.icon-game:before { + content: "\e6df"; +} + +.icon-gift:before { + content: "\e681"; +} + +.icon-sign-in:before { + content: "\e60d"; +} + +.icon-nav_profile:before { + content: "\e669"; +} + +.icon-vip-fill:before { + content: "\e78f"; +} + +.icon-f-coupon:before { + content: "\e778"; +} + +.icon-collection:before { + content: "\e6a5"; +} + .icon-clear:before { content: "\e649"; } @@ -46,6 +74,7 @@ } + /**global style**/ image{ max-width: 100%; diff --git a/miniprogram/app.ts b/miniprogram/app.ts index 7ef2a21..def0bb6 100644 --- a/miniprogram/app.ts +++ b/miniprogram/app.ts @@ -6,31 +6,41 @@ App({ onLaunch() { this.updateUserInfo(); }, + initLoginInfo(resolve, reject) { + wx.login({ + fail: reject, + success: (e) => { + if (e.code) { + info(e.code).then(userinfo => { + if (userinfo.token) { + wx.setStorageSync("user-token", userinfo.token) + } + this.globalData.userInfo = userinfo; + resolve(userinfo); + }).catch(reject) + } + } + }) + }, updateUserInfo() { return new Promise((resolve, reject) => { // 展示本地存储能力 const token = wx.getStorageSync('user-token') if (token) { this.globalData.token = token; - info().then(userinfo => { + info('', false).then(userinfo => { + console.log(userinfo) this.globalData.userInfo = userinfo; resolve(userinfo); - }).catch(reject) - } else { - wx.login({ - fail: reject, - success: (e) => { - if (e.code) { - info(e.code).then(userinfo => { - if (userinfo.token) { - wx.setStorageSync("user-token", userinfo.token) - } - this.globalData.userInfo = userinfo; - resolve(userinfo); - }).catch(reject) - } + }).catch((e) => { + if (e.code == 403) { + this.initLoginInfo(resolve, reject) + return; } + reject(e) }) + } else { + this.initLoginInfo(resolve, reject) } }) } diff --git a/miniprogram/assets/font/demo_index.html b/miniprogram/assets/font/demo_index.html index c6dce36..761e538 100644 --- a/miniprogram/assets/font/demo_index.html +++ b/miniprogram/assets/font/demo_index.html @@ -54,6 +54,48 @@
    +
  • + +
    game
    +
    
    +
  • + +
  • + +
    gift
    +
    
    +
  • + +
  • + +
    sign-in
    +
    
    +
  • + +
  • + +
    个人信息
    +
    
    +
  • + +
  • + +
    vip-fill
    +
    
    +
  • + +
  • + +
    f-coupon
    +
    
    +
  • + +
  • + +
    collection
    +
    
    +
  • +
  • clear
    @@ -120,9 +162,9 @@
    @font-face {
       font-family: 'iconfont';
    -  src: url('iconfont.woff2?t=1669601953874') format('woff2'),
    -       url('iconfont.woff?t=1669601953874') format('woff'),
    -       url('iconfont.ttf?t=1669601953874') format('truetype');
    +  src: url('iconfont.woff2?t=1669628868947') format('woff2'),
    +       url('iconfont.woff?t=1669628868947') format('woff'),
    +       url('iconfont.ttf?t=1669628868947') format('truetype');
     }
     

    第二步:定义使用 iconfont 的样式

    @@ -148,6 +190,69 @@
      +
    • + +
      + game +
      +
      .icon-game +
      +
    • + +
    • + +
      + gift +
      +
      .icon-gift +
      +
    • + +
    • + +
      + sign-in +
      +
      .icon-sign-in +
      +
    • + +
    • + +
      + 个人信息 +
      +
      .icon-nav_profile +
      +
    • + +
    • + +
      + vip-fill +
      +
      .icon-vip-fill +
      +
    • + +
    • + +
      + f-coupon +
      +
      .icon-f-coupon +
      +
    • + +
    • + +
      + collection +
      +
      .icon-collection +
      +
    • +
    • @@ -247,6 +352,62 @@
        +
      • + +
        game
        +
        #icon-game
        +
      • + +
      • + +
        gift
        +
        #icon-gift
        +
      • + +
      • + +
        sign-in
        +
        #icon-sign-in
        +
      • + +
      • + +
        个人信息
        +
        #icon-nav_profile
        +
      • + +
      • + +
        vip-fill
        +
        #icon-vip-fill
        +
      • + +
      • + +
        f-coupon
        +
        #icon-f-coupon
        +
      • + +
      • + +
        collection
        +
        #icon-collection
        +
      • +
      diff --git a/miniprogram/service/user-api.ts b/miniprogram/service/user-api.ts index d72f9b5..fa610e4 100644 --- a/miniprogram/service/user-api.ts +++ b/miniprogram/service/user-api.ts @@ -20,6 +20,6 @@ export function sign() { /** * 用户信息 */ -export function info(code: string = '') { - return request('/user/info', { code }, "GET"); +export function info(code: string = '', showLogin = true) { + return request('/user/info', { code }, "GET", showLogin); } \ No newline at end of file diff --git a/miniprogram/utils/request.ts b/miniprogram/utils/request.ts index 5052957..f66b150 100644 --- a/miniprogram/utils/request.ts +++ b/miniprogram/utils/request.ts @@ -27,7 +27,7 @@ type ApiResponse = { } type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" -function request(api: string, data: any = null, method: HttpMethod = 'POST') { +function request(api: string, data: any = null, method: HttpMethod = 'POST',autoShowLogin: boolean = true) { const header: { [key: string]: string } = {} @@ -61,7 +61,7 @@ function request(api: string, data: any = null, method: HttpMethod = 'POST') const result = res.data // 验证接口是否正确 if (result.code !== 0) { - if (result.code === 403) { + if (result.code === 403 && autoShowLogin) { wx.switchTab({ url: '/pages/personal/personal' }) diff --git a/typings/index.d.ts b/typings/index.d.ts index 5c1fc82..b7ad782 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -6,5 +6,6 @@ interface IAppOption { token?: string } userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback, - updateUserInfo:()=>Promise + updateUserInfo: () => Promise + initLoginInfo: (resolve: (value: any) => void, reject: (reason: any) => void) => void } \ No newline at end of file