网站/小程序/APP个性化定制开发,二开,改版等服务,加扣:8582-36016

微信小程序车贷项目源码案例

应用介绍

    目录

作者ruralist-siyi,源码carloan-weixinapp,这是采用原生实现的车贷微信小程序项目。


 

 部分代码
// utils/request.js: 统一请求封装,基于promiseimport {getRandomStr} from './index'import Notify from '../components/vant-weapp/dist/notify/notify';const baseUrl = 'http://47.98.239.167:8035';export function createApiRequest(options) {
  const {method = 'POST', url, callback, data = {}, checkToken = true} = options;
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseUrl + url,
      method: method,
      data: {
        tenantId: '0001',
        terminalType: '1',
        serialId: getRandomStr(),
        token: checkToken ? wx.getStorageSync('token') : null,
        ...data
      },
      header: {
        'Content-Type': 'application/json;charset=UTF-8',
      },
      success: (response) => {
        if (response.statusCode >= 200 && response.statusCode < 300) {
          const code = response.data.code;
          if (code === "000000") {
            const result = response.data.data;
            resolve(result);
          } else {
            Notify(response.data.message || '请求错误');
          }
        } else if (response.statusCode === 401) {
          Notify('登录超时,请重新登录');
          wx.navigateTo({
            url: '/pages/login/login'
          })
        }
      },
      fail: (response) => {
        const errMsg = response.errMsg || '请求错误';
        Notify(errMsg);
        reject();
      },
      complete: () => {
        callback && callback();
      }
    })
  })}// login方法
  login: function (e) {
    const {detail: {value}} = e;
    this.changeLoading();
    createApiRequest({
      url: '/auth/user/login',
      data: value,
      callback: this.changeLoading,
      checkToken: false
    }).then((data) => {
      if (data) {
        const {token} = data;
        wx.setStorageSync('token', token);
        wx.setStorageSync('userInfo', JSON.stringify(data));
        wx.switchTab({
          url: '/pages/home/home'
        })
      }
    })
  }




立即下载

温馨提示! 你需要支付 2.00P币后才可以下载

评论 共有 0 条评论

暂无评论
0
0
0
立即
投稿
发表
评论
返回
顶部