微信小程序车贷项目源码案例
应用介绍
作者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' }) } }) }

©软件著作权归作者所有。本站所有内容均来源于网络,不得违法使用,仅供学习使用,请支持正版!
转载请注明出处: 662P » 微信小程序车贷项目源码案例
发表评论 取消回复