index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // 引入全局mixin
  2. import mixin from './libs/mixin/mixin.js'
  3. // 引入关于是否mixin集成小程序分享的配置
  4. // import wxshare from './libs/mixin/mpShare.js'
  5. // 全局挂载引入http相关请求拦截插件
  6. import http from './libs/request'
  7. function wranning(str) {
  8. // 开发环境进行信息输出,主要是一些报错信息
  9. // 这个环境的来由是在程序编写时候,点击hx编辑器运行调试代码的时候,详见:
  10. // https://uniapp.dcloud.io/frame?id=%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e5%92%8c%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83
  11. if (process.env.NODE_ENV === 'development') {
  12. console.warn(str)
  13. }
  14. }
  15. // 尝试判断在根目录的/store中是否有$u.mixin.js,此文件uView默认为需要挂在到全局的vuex的state变量
  16. // HX2.6.11版本,放到try中,控制台依然会警告,暂时不用此方式,
  17. // let vuexStore = {};
  18. // try {
  19. // vuexStore = require("@/store/$u.mixin.js");
  20. // } catch (e) {
  21. // //TODO handle the exception
  22. // }
  23. // post类型对象参数转为get类型url参数
  24. import queryParams from './libs/function/queryParams.js'
  25. // 路由封装
  26. import route from './libs/function/route.js'
  27. // 时间格式化
  28. import timeFormat from './libs/function/timeFormat.js'
  29. // 时间戳格式化,返回多久之前
  30. import timeFrom from './libs/function/timeFrom.js'
  31. // 颜色渐变相关,colorGradient-颜色渐变,hexToRgb-十六进制颜色转rgb颜色,rgbToHex-rgb转十六进制
  32. import colorGradient from './libs/function/colorGradient.js'
  33. // 生成全局唯一guid字符串
  34. import guid from './libs/function/guid.js'
  35. // 主题相关颜色,info|success|warning|primary|default|error,此颜色已在uview.scss中定义,但是为js中也能使用,故也定义一份
  36. import color from './libs/function/color.js'
  37. // 根据type获取图标名称
  38. import type2icon from './libs/function/type2icon.js'
  39. // 打乱数组的顺序
  40. import randomArray from './libs/function/randomArray.js'
  41. // 对象和数组的深度克隆
  42. import deepClone from './libs/function/deepClone.js'
  43. // 对象深度拷贝
  44. import deepMerge from './libs/function/deepMerge.js'
  45. // 添加单位
  46. import addUnit from './libs/function/addUnit.js'
  47. // 规则检验
  48. import test from './libs/function/test.js'
  49. // 随机数
  50. import random from './libs/function/random.js'
  51. // 去除空格
  52. import trim from './libs/function/trim.js'
  53. // toast提示,对uni.showToast的封装
  54. import toast from './libs/function/toast.js'
  55. // 获取父组件参数
  56. import getParent from './libs/function/getParent.js'
  57. // 获取整个父组件
  58. import $parent from './libs/function/$parent.js'
  59. // 获取sys()和os()工具方法
  60. // 获取设备信息,挂载到$u的sys()(system的缩写)属性中,
  61. // 同时把安卓和ios平台的名称"ios"和"android"挂到$u.os()中,方便取用
  62. import {sys, os} from './libs/function/sys.js'
  63. // 防抖方法
  64. import debounce from './libs/function/debounce.js'
  65. // 节流方法
  66. import throttle from './libs/function/throttle.js'
  67. // 配置信息
  68. import config from './libs/config/config.js'
  69. // 各个需要fixed的地方的z-index配置文件
  70. import zIndex from './libs/config/zIndex.js'
  71. const $u = {
  72. queryParams: queryParams,
  73. route: route,
  74. timeFormat: timeFormat,
  75. date: timeFormat, // 另名date
  76. timeFrom,
  77. colorGradient: colorGradient.colorGradient,
  78. guid,
  79. color,
  80. sys,
  81. os,
  82. type2icon,
  83. randomArray,
  84. wranning,
  85. get: http.get,
  86. post: http.post,
  87. put: http.put,
  88. 'delete': http.delete,
  89. hexToRgb: colorGradient.hexToRgb,
  90. rgbToHex: colorGradient.rgbToHex,
  91. test,
  92. random,
  93. deepClone,
  94. deepMerge,
  95. getParent,
  96. $parent,
  97. addUnit,
  98. trim,
  99. type: ['primary', 'success', 'error', 'warning', 'info'],
  100. http,
  101. toast,
  102. config, // uView配置信息相关,比如版本号
  103. zIndex,
  104. debounce,
  105. throttle,
  106. }
  107. const install = Vue => {
  108. Vue.mixin(mixin)
  109. if (Vue.prototype.openShare) {
  110. Vue.mixin(mpShare);
  111. }
  112. // Vue.mixin(vuexStore);
  113. // 时间格式化,同时两个名称,date和timeFormat
  114. Vue.filter('timeFormat', (timestamp, format) => {
  115. return timeFormat(timestamp, format)
  116. })
  117. Vue.filter('date', (timestamp, format) => {
  118. return timeFormat(timestamp, format)
  119. })
  120. // 将多久以前的方法,注入到全局过滤器
  121. Vue.filter('timeFrom', (timestamp, format) => {
  122. return timeFrom(timestamp, format)
  123. })
  124. Vue.prototype.$u = $u
  125. }
  126. export default {
  127. install
  128. }