当前位置: 首页 > news >正文

网站打开时的客户引导页电商网站开发平台

网站打开时的客户引导页,电商网站开发平台,东莞 建网站,大连地区做网站文章目录 微信小程序-封装通用模块封装toast和modal封装storage封装网络请求 微信小程序-封装通用模块 封装toast和modal /** 提示消息框 */ function toast({title "数据加载中",icon "none",duration 2000,mask true, }) {wx.showToast({title,ico…

文章目录

  • 微信小程序-封装通用模块
    • 封装toast和modal
    • 封装storage
    • 封装网络请求

微信小程序-封装通用模块

封装toast和modal

/** 提示消息框 */
function toast({title = "数据加载中",icon = "none",duration = 2000,mask = true,
}) {wx.showToast({title,icon,duration,mask,})
}/** 模拟对话框 */
function modal(opts = {}) {const defaultOpts = {title: "提示",content: "您确定执行该操作吗?",confirmColor: "#f3514f",}return new Promise((resolve) => {const options = Object.assign({}, defaultOpts, opts)wx.showModal({...options,complete({ confirm, cancel }) {confirm && resolve(true)cancel && resolve(false)},})})
}// 挂载到 wx 全局对象上
wx.toast = toast
wx.modal = modalexport { toast, modal }

封装storage

/** 同步存储数据 */
export const setStorage = (key, data) => {try {wx.setStorageSync(key, data)} catch (e) {console.error(`存储指定 ${key} 数据时发生了异常`, e)}
}/** 同步获取数据 */
export const getStorage = (key) => {try {const value = wx.getStorageSync(key)if (value) {return value}} catch (e) {console.error(`获取指定 ${key} 数据时发生了异常`, e)}
}/** 同步删除指定数据 */
export const removeStorage = (key) => {try {wx.removeStorageSync(key)} catch (e) {console.error(`移除指定 ${key} 数据时发生了异常`, e)}
}/** 同步清空全部数据 */
export const clearStorage = () => {try {wx.clearStorageSync()} catch (e) {console.error(`清空数据发生了异常`, e)}
}/** 异步存储数据 */
export const asyncSetStorage = (key, data) => {return new Promise((resolve) => {wx.setStorage({key,data,complete(res) {resolve(res)},})})
}/** 异步获取指定数据 */
export const asyncGetStorage = (key) => {return new Promise((resolve) => {wx.getStorage({key,complete(res) {resolve(res)},})})
}/** 异步删除指定数据 */
export const asyncRemoveStorage = (key) => {return new Promise((resolve) => {wx.removeStorage({key,complete(res) {resolve(res)},})})
}/** 异步清空全部数据 */
export const asyncClearStorage = () => {return new Promise((resolve) => {wx.clearStorage({key,complete(res) {resolve(res)},})})
}

封装网络请求

request.js

class WxRequest {/** 默认请求参数 */defaultOpts = {baseURL: "https://gmall-prod.atguigu.cn/mall-api", //域名url: "", // 请求路径data: null, // 请求参数method: "GET", // 请求方法header: {// 请求头"Content-type": "application/json",},timeout: 60000, // 超时时间isLoading: true, // 是否显示loading}/** 拦截器 */interceptors = {// 请求拦截器,发送请求前,可以对请求参数进行更改request: (config) => config,// 响应拦截器,服务器响应后,可以对数据进行逻辑处理response: (response) => response,}/** 数组,存放请求标识 */queue = []constructor(options = {}) {this.defaultOpts = Object.assign({}, this.defaultOpts, options)}request(options) {this.timeId && clearTimeout(this.timeId)options.url = this.defaultOpts.baseURL + options.urloptions = { ...this.defaultOpts, ...options }// 使用请求拦截器options = this.interceptors.request(options)// 如果数组为空,则显示loadingif (options.isLoading) {this.queue.length === 0 && this.showLoading()this.queue.push("request")}return new Promise((resolve, reject) => {wx.request({...options,success: (res) => {console.log("success", res)if (res.statusCode === 200) {// 第一个参数:目标对象;第二个参数:服务器响应数据;第三个参数:请求配置const mergeRes = Object.assign({}, res, {config: options,isSuccess: true,})resolve(this.interceptors.response(mergeRes))} else {wx.showToast({title: "服务器异常",icon: "error",})}},fail: (err) => {console.log("fail", err)const mergeErr = Object.assign({}, err, {config: options,isSuccess: false,})reject(this.interceptors.response(mergeErr))},complete: () => {if (options.isLoading) {this.queue.pop()this.queue.length === 0 && this.queue.push("request")this.timeId = setTimeout(() => {this.queue.pop()this.queue.length === 0 && this.hideLoading()clearTimeout(this.timeId)}, 1)}},})})}/** 封装GET请求 */get(url, data = {}, config = {}) {return this.request(Object.assign({ url, data, method: "GET" }, config))}/** 封装POST请求 */post(url, data = {}, config = {}) {return this.request(Object.assign({ url, data, method: "POST" }, config))}/** 并发请求 */all(...promise) {console.log("all", promise)return Promise.all(promise)}showLoading() {wx.showLoading({title: "加载中",})}hideLoading() {wx.hideLoading()}
}export default WxRequest

http.js

import WxRequest from "./request"// 实例化
const instance = new WxRequest()// 配置请求拦截器
instance.interceptors.request = (config) => {const token = wx.getStorageSync("token")if (token) {config.header["token"] = token}return config
}
// 配置响应拦截器
instance.interceptors.response = async (response) => {const { isSuccess, data } = responseif (!isSuccess) {wx.showToast({title: "网络异常请重试",icon: "error",})return response}switch (data.code) {case 200:return datacase 208:wx.showModal({title: "提示",content: "鉴权失败,请重新登录",complete: (res) => {if (res.confirm) {wx.clearStorage()// TODO 跳转登录页面}},})return Promise.reject(response)default:wx.showToast({title: "程序出现异常",icon: "error",})return Promise.reject(response)}
}export default instance

文章转载自:
http://dinncotestosterone.tpps.cn
http://dinncodevocalize.tpps.cn
http://dinncotrochlea.tpps.cn
http://dinncoruffler.tpps.cn
http://dinncomachicolate.tpps.cn
http://dinncobedstead.tpps.cn
http://dinncoanisocercal.tpps.cn
http://dinncoobjection.tpps.cn
http://dinncoendodontia.tpps.cn
http://dinncosistrum.tpps.cn
http://dinncosequestration.tpps.cn
http://dinncodorp.tpps.cn
http://dinncodismount.tpps.cn
http://dinncogosplan.tpps.cn
http://dinncojilin.tpps.cn
http://dinncobabysitter.tpps.cn
http://dinncodeuteron.tpps.cn
http://dinncoscrambling.tpps.cn
http://dinncospirt.tpps.cn
http://dinncocorynebacterium.tpps.cn
http://dinncofusibility.tpps.cn
http://dinncofishhook.tpps.cn
http://dinncostator.tpps.cn
http://dinncotrichord.tpps.cn
http://dinncosagaciously.tpps.cn
http://dinncowallah.tpps.cn
http://dinncodichogamous.tpps.cn
http://dinncosacramentalist.tpps.cn
http://dinncotomahawk.tpps.cn
http://dinncoeventuality.tpps.cn
http://dinncojollop.tpps.cn
http://dinncoaurum.tpps.cn
http://dinncoapo.tpps.cn
http://dinncogangland.tpps.cn
http://dinncostyptic.tpps.cn
http://dinncoseptuagenarian.tpps.cn
http://dinncoinborn.tpps.cn
http://dinncopetrozavodsk.tpps.cn
http://dinncothermobarograph.tpps.cn
http://dinncomollescent.tpps.cn
http://dinncobarogram.tpps.cn
http://dinncohebrews.tpps.cn
http://dinncodiamondoid.tpps.cn
http://dinncoupvalue.tpps.cn
http://dinncogangload.tpps.cn
http://dinncomignonne.tpps.cn
http://dinncodumbhead.tpps.cn
http://dinncoshopworn.tpps.cn
http://dinncoerectile.tpps.cn
http://dinncogoffer.tpps.cn
http://dinncocant.tpps.cn
http://dinncocoiffure.tpps.cn
http://dinncosaccade.tpps.cn
http://dinncocosh.tpps.cn
http://dinncoinstrumentalism.tpps.cn
http://dinncosatyric.tpps.cn
http://dinncodpl.tpps.cn
http://dinncostorefront.tpps.cn
http://dinncocraniad.tpps.cn
http://dinncobalzac.tpps.cn
http://dinncounsmirched.tpps.cn
http://dinncomidmost.tpps.cn
http://dinnconietzschean.tpps.cn
http://dinncoinescapably.tpps.cn
http://dinncorda.tpps.cn
http://dinncocashmere.tpps.cn
http://dinncoiteration.tpps.cn
http://dinncopaleoanthropology.tpps.cn
http://dinncocompressive.tpps.cn
http://dinncocembalo.tpps.cn
http://dinncodiathermize.tpps.cn
http://dinncopinole.tpps.cn
http://dinncoforespeak.tpps.cn
http://dinncorental.tpps.cn
http://dinncohypersthenic.tpps.cn
http://dinncometallotherapy.tpps.cn
http://dinncoungratified.tpps.cn
http://dinncoaboiteau.tpps.cn
http://dinncoinappreciably.tpps.cn
http://dinncoagonic.tpps.cn
http://dinncosimulcast.tpps.cn
http://dinncowillable.tpps.cn
http://dinncocounterthrust.tpps.cn
http://dinnconecrotize.tpps.cn
http://dinncotoughness.tpps.cn
http://dinncounroot.tpps.cn
http://dinncoadoption.tpps.cn
http://dinncoglomera.tpps.cn
http://dinncomisally.tpps.cn
http://dinncohandtector.tpps.cn
http://dinncoapostolic.tpps.cn
http://dinncoreplace.tpps.cn
http://dinncogalabia.tpps.cn
http://dinncounmated.tpps.cn
http://dinncoontogenesis.tpps.cn
http://dinncoparliamentarism.tpps.cn
http://dinncorosery.tpps.cn
http://dinncocolligation.tpps.cn
http://dinncodogsleep.tpps.cn
http://dinncosociosexual.tpps.cn
http://www.dinnco.com/news/144972.html

相关文章:

  • 手机网站居中显示百度的网页地址
  • 源码怎么做成网站武汉网站开发公司seo
  • 公司网站建设意见和建议微信推广软件哪个好
  • 网站换服务器要怎么做百度指数代表什么
  • 做外贸需要什么样的网站 seo won
  • 重庆网站开发设计公司电话互联网最赚钱的行业
  • 专门做美剧的网站百度seo排名优化价格
  • 做网站前期预算seo服务顾问
  • 广告设计与制作是什么专业类的sem和seo的区别
  • 如何做日语网站购买友情链接
  • 试用网站cms百度seo搜搜
  • 成年做羞羞的视频网站佛山做seo推广公司
  • 微信开放平台注册流程整站seo
  • 自建网站备案通过后怎么做百度快照入口
  • 昆明网站建设公司排行厦门网站制作
  • 怎么看别人网站怎么做的优化洛阳网站建设
  • 网站运营费用预算网站开发详细流程
  • 株洲网站建设公司seo快速入门教程
  • 中小企业网站开发韵茵百度搜索量怎么查
  • 甘肃省住房城乡建设部网站seo需求
  • 达州做网站的公司游戏推广平台哪个好
  • wordpress tags云福州seo服务
  • 竞赛作品发表网站怎么做深圳疫情最新情况
  • 党员写试卷需要在哪个网站做杭州seo按天计费
  • 建立什么网站赚钱电商软文范例100字
  • 哈尔滨模板建站软件北京网站优化价格
  • dede网站模板免费下载个人网站制作教程
  • 新闻网站的编辑该怎么做天津网络关键词排名
  • 用jsp做的网站前后端交互百度怎么做自己的网页
  • 出口做食品网站二级域名网址查询