main.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. import Vue from 'vue'
  2. import store from './store'
  3. import App from './App'
  4. import util from './js/util.js'
  5. import until from './js/until.js'
  6. import bindid from './js/bindid.js'
  7. import uView from '@/uni_modules/uview-ui'
  8. import homeApi from '@/api/home/index.js'
  9. import paycenter from '@/api/paycenter/paycenter.js'
  10. // 引入 tob-less
  11. import setupTobLess from '@/uni_modules/tob-less/index.js'
  12. import siteinfo from "@/siteinfo.js"
  13. import author from "@/author.js"
  14. import sharebox from "@/components/sharebox/sharebox.vue"
  15. // #ifdef MP-WEIXIN
  16. let mpShare = require('@/uni_modules/uview-ui/libs/mixin/mpShare.js');
  17. // #endif
  18. App.mpType = 'app'
  19. Vue.component('sharebox', sharebox)
  20. const showToast = (title, duration = 2000, mask = false, icon = 'none') => {
  21. uni.showToast({
  22. title,
  23. duration,
  24. mask,
  25. icon
  26. });
  27. }
  28. /**
  29. * 因工具函数属于公司资产, 所以直接在Vue实例挂载几个常用的函数
  30. * 所有测试用数据均存放于根目录json.js
  31. *
  32. * css部分使用了App.vue下的全局样式和iconfont图标,有需要图标库的可以留言。
  33. * 示例使用了uni.scss下的变量, 除变量外已尽量移除特有语法,可直接替换为其他预处理器使用
  34. */
  35. const msg = (title, duration = 2000, mask = false, icon = 'none') => {
  36. //统一提示方便全局修改
  37. if (Boolean(title) === false) {
  38. return;
  39. }
  40. uni.showToast({
  41. title,
  42. duration,
  43. mask,
  44. icon
  45. });
  46. }
  47. const json = type => {}
  48. const prePage = () => {
  49. let pages = getCurrentPages();
  50. let prePage = pages[pages.length - 2];
  51. // #ifdef H5
  52. return prePage;
  53. // #endif
  54. if (prePage && prePage.$vm) {
  55. return prePage.$vm;
  56. } else {
  57. return null;
  58. }
  59. }
  60. Vue.config.productionTip = false
  61. Vue.prototype.$store = store;
  62. //获取登录用户ID
  63. Vue.prototype.$getuid = () => {
  64. let userInfo = uni.getStorageSync('userInfo');
  65. if (userInfo) {
  66. return userInfo.id;
  67. } else {
  68. return 0;
  69. }
  70. }
  71. // #ifdef H5
  72. const getUrlParms = name => {
  73. const reg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`)
  74. const r = window.location.search.substr(1).match(reg)
  75. if (r !== null)
  76. return unescape(r[2])
  77. return null
  78. }
  79. Vue.prototype.$getUrlParms = getUrlParms //全局配置
  80. // #endif
  81. //判断是否是微信浏览器的函数
  82. Vue.prototype.isWeiXin = function() {
  83. // #ifdef H5
  84. var ua = window.navigator.userAgent.toLowerCase();
  85. if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  86. return true;
  87. } else {
  88. // 普通浏览器
  89. return false;
  90. }
  91. // #endif
  92. return false;
  93. }
  94. //广告时间
  95. Vue.prototype.$adtime = {
  96. mvideo_time: 0,
  97. pscreen_time: 0,
  98. banner_time: 0
  99. };
  100. Vue.prototype.$paycenter = paycenter;
  101. Vue.prototype.$primarys = {
  102. "A": "#ff8903",
  103. "B": "#e52340",
  104. "C": "#ffd100",
  105. "D": "#4B086D",
  106. "E": "#014872",
  107. "F": "#067d68",
  108. "G": "#56AB2F",
  109. }
  110. Vue.prototype.$api = {
  111. msg,
  112. json,
  113. prePage
  114. };
  115. Vue.prototype.$util = util;
  116. Vue.prototype.$until = until;
  117. Vue.prototype.$bindid = bindid;
  118. Vue.prototype.$Toast = showToast;
  119. Vue.prototype.$siteinfo = siteinfo
  120. Vue.prototype.$author = author
  121. Vue.prototype.$siteinfo.root_img = siteinfo.siteroot;
  122. Vue.prototype.$siteinfo.root_rich_img = siteinfo.siteroot;
  123. if (process.env.NODE_ENV === 'development') {
  124. Vue.prototype.$siteinfo.h5_siteroot = siteinfo.siteroot;
  125. } else {
  126. //生产环境
  127. // #ifdef H5
  128. let httpurl = ''
  129. if (location.href.indexOf('https') != -1) {
  130. httpurl = `https://${window.location.host}`
  131. } else {
  132. httpurl = `http://${window.location.host}` //全局配置
  133. }
  134. Vue.prototype.$siteinfo.h5_siteroot = httpurl
  135. Vue.prototype.$siteinfo.root_rich_img = httpurl;
  136. // #endif
  137. }
  138. if (Vue.prototype.$author.we7_v2 == 1) {
  139. // #ifdef H5
  140. Vue.prototype.$siteinfo.root_img = Vue.prototype.$siteinfo.h5_siteroot + "/addons/yq_breedingmall/public"
  141. // #endif
  142. // #ifndef H5
  143. Vue.prototype.$siteinfo.root_img = Vue.prototype.$siteinfo.root_img + "/addons/yq_breedingmall/public"
  144. // #endif
  145. }
  146. Vue.prototype.$config = {
  147. app: {
  148. position: 0
  149. }
  150. } //全局配置
  151. Vue.prototype.platform = 0
  152. Vue.prototype.$uuid = 0
  153. // #ifdef H5
  154. Vue.config.ignoredElements = [...Vue.config.ignoredElements, 'wx-open-launch-weapp']
  155. // #endif
  156. const init_data = (data, fun) => {
  157. Vue.prototype.$config = data;
  158. if (fun) {
  159. fun(data);
  160. }
  161. }
  162. Vue.prototype.$init_data = init_data
  163. Vue.prototype.$cache_config_info_key = 'config_info_key';
  164. const getprimary = () => {
  165. let config = until.myCache(Vue.prototype.$cache_config_info_key);
  166. if (config) {
  167. return config.primary
  168. }
  169. return '#56AB2F'
  170. }
  171. Vue.prototype.$getprimary = getprimary
  172. Vue.prototype.$theme = {
  173. primary: getprimary()
  174. }
  175. const init_config = (rtype = 2, fun = null) => {
  176. let config = until.myCache(Vue.prototype.$cache_config_info_key);
  177. if (rtype == 1) {
  178. until.myCache(Vue.prototype.$cache_config_info_key, null)
  179. config = null;
  180. }
  181. if (config) {
  182. Vue.prototype.$init_data(config, fun);
  183. } else {
  184. homeApi.home().then(res => {
  185. if (res.status == 200) {
  186. // #ifdef MP-WEIXIN
  187. uni.$u.mpShare = {
  188. title: res.data.sharedata.title, // 默认为小程序名称,可自定义
  189. path: '', // 默认为当前页面路径,一般无需修改,QQ小程序不支持
  190. // 分享图标,路径可以是本地文件路径、代码包文件路径或者网络图片路径。
  191. // 支持PNG及JPG,默认为当前页面的截图
  192. imageUrl: res.data.sharedata.imageUrl
  193. }
  194. // #endif
  195. res.data['primary'] = Vue.prototype.$primarys[res.data.initAppTheme]
  196. Vue.prototype.$theme.primary = res.data['primary']
  197. until.myCache(Vue.prototype.$cache_config_info_key, res.data, 60 * 10);
  198. setupTobLess(Vue, {
  199. initAppTheme: res.data.initAppTheme
  200. })
  201. Vue.prototype.$init_data(res.data, fun);
  202. } else {
  203. uni.showToast({
  204. icon: 'none',
  205. title: res.data
  206. })
  207. }
  208. })
  209. }
  210. }
  211. Vue.prototype.$init_config = init_config
  212. const start = () => {
  213. setupTobLess(Vue, {
  214. initAppTheme: "G"
  215. })
  216. // #ifdef H5
  217. Vue.prototype.$uuid = Vue.prototype.$getUrlParms("uuid")
  218. Vue.prototype.$bindid.getbindid({
  219. pid: Vue.prototype.$getUrlParms("pid")
  220. }, Vue.prototype.$store);
  221. // #endif
  222. Vue.prototype.$init_config(1);
  223. uni.setStorageSync('tabbar', null)
  224. const res = uni.getSystemInfoSync();
  225. if (res.platform == 'android') {
  226. Vue.prototype.platform = 1
  227. } else if (res.platform == 'ios') {
  228. Vue.prototype.platform = 2
  229. }
  230. //全局配置
  231. // #ifdef MP-WEIXIN
  232. Vue.mixin(mpShare)
  233. // #endif
  234. Vue.use(uView);
  235. const app = new Vue({
  236. ...App
  237. })
  238. app.$mount()
  239. }
  240. start();