main.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. console.log(r,'r');
  76. if (r !== null)
  77. return unescape(r[2])
  78. return null
  79. }
  80. Vue.prototype.$getUrlParms = getUrlParms //全局配置
  81. // #endif
  82. //判断是否是微信浏览器的函数
  83. Vue.prototype.isWeiXin = function() {
  84. // #ifdef H5
  85. var ua = window.navigator.userAgent.toLowerCase();
  86. if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  87. return true;
  88. } else {
  89. // 普通浏览器
  90. return false;
  91. }
  92. // #endif
  93. return false;
  94. }
  95. //广告时间
  96. Vue.prototype.$adtime = {
  97. mvideo_time: 0,
  98. pscreen_time: 0,
  99. banner_time: 0
  100. };
  101. Vue.prototype.$paycenter = paycenter;
  102. Vue.prototype.$primarys = {
  103. "A": "#ff8903",
  104. "B": "#e52340",
  105. "C": "#ffd100",
  106. "D": "#4B086D",
  107. "E": "#014872",
  108. "F": "#067d68",
  109. "G": "#56AB2F",
  110. }
  111. Vue.prototype.$api = {
  112. msg,
  113. json,
  114. prePage
  115. };
  116. Vue.prototype.$util = util;
  117. Vue.prototype.$until = until;
  118. Vue.prototype.$bindid = bindid;
  119. Vue.prototype.$Toast = showToast;
  120. Vue.prototype.$siteinfo = siteinfo
  121. Vue.prototype.$author = author
  122. Vue.prototype.$siteinfo.root_img = siteinfo.siteroot;
  123. Vue.prototype.$siteinfo.root_rich_img = siteinfo.siteroot;
  124. if (process.env.NODE_ENV === 'development') {
  125. Vue.prototype.$siteinfo.h5_siteroot = siteinfo.siteroot;
  126. } else {
  127. //生产环境
  128. // #ifdef H5
  129. let httpurl = ''
  130. if (location.href.indexOf('https') != -1) {
  131. httpurl = `https://${window.location.host}`
  132. } else {
  133. httpurl = `http://${window.location.host}` //全局配置
  134. }
  135. Vue.prototype.$siteinfo.h5_siteroot = httpurl
  136. Vue.prototype.$siteinfo.root_rich_img = httpurl;
  137. // #endif
  138. }
  139. if (Vue.prototype.$author.we7_v2 == 1) {
  140. // #ifdef H5
  141. Vue.prototype.$siteinfo.root_img = Vue.prototype.$siteinfo.h5_siteroot + "/addons/yq_breedingmall/public"
  142. // #endif
  143. // #ifndef H5
  144. Vue.prototype.$siteinfo.root_img = Vue.prototype.$siteinfo.root_img + "/addons/yq_breedingmall/public"
  145. // #endif
  146. }
  147. Vue.prototype.$config = {
  148. app: {
  149. position: 0
  150. }
  151. } //全局配置
  152. Vue.prototype.platform = 0
  153. Vue.prototype.$uuid = 0
  154. // #ifdef H5
  155. Vue.config.ignoredElements = [...Vue.config.ignoredElements, 'wx-open-launch-weapp']
  156. // #endif
  157. const init_data = (data, fun) => {
  158. Vue.prototype.$config = data;
  159. if (fun) {
  160. fun(data);
  161. }
  162. }
  163. Vue.prototype.$init_data = init_data
  164. Vue.prototype.$cache_config_info_key = 'config_info_key';
  165. const getprimary = () => {
  166. let config = until.myCache(Vue.prototype.$cache_config_info_key);
  167. if (config) {
  168. return config.primary
  169. }
  170. return '#56AB2F'
  171. }
  172. Vue.prototype.$getprimary = getprimary
  173. Vue.prototype.$theme = {
  174. primary: getprimary()
  175. }
  176. const init_config = (rtype = 2, fun = null) => {
  177. let config = until.myCache(Vue.prototype.$cache_config_info_key);
  178. if (rtype == 1) {
  179. until.myCache(Vue.prototype.$cache_config_info_key, null)
  180. config = null;
  181. }
  182. if (config) {
  183. Vue.prototype.$init_data(config, fun);
  184. } else {
  185. homeApi.home().then(res => {
  186. if (res.status == 200) {
  187. // #ifdef MP-WEIXIN
  188. uni.$u.mpShare = {
  189. title: res.data.sharedata.title, // 默认为小程序名称,可自定义
  190. path: '', // 默认为当前页面路径,一般无需修改,QQ小程序不支持
  191. // 分享图标,路径可以是本地文件路径、代码包文件路径或者网络图片路径。
  192. // 支持PNG及JPG,默认为当前页面的截图
  193. imageUrl: res.data.sharedata.imageUrl
  194. }
  195. // #endif
  196. res.data['primary'] = Vue.prototype.$primarys[res.data.initAppTheme]
  197. Vue.prototype.$theme.primary = res.data['primary']
  198. until.myCache(Vue.prototype.$cache_config_info_key, res.data, 60 * 10);
  199. setupTobLess(Vue, {
  200. initAppTheme: res.data.initAppTheme
  201. })
  202. Vue.prototype.$init_data(res.data, fun);
  203. } else {
  204. uni.showToast({
  205. icon: 'none',
  206. title: res.data
  207. })
  208. }
  209. })
  210. }
  211. }
  212. Vue.prototype.$init_config = init_config
  213. const start = () => {
  214. setupTobLess(Vue, {
  215. initAppTheme: "G"
  216. })
  217. // #ifdef H5
  218. Vue.prototype.$uuid = Vue.prototype.$getUrlParms("uuid")
  219. console.log(Vue.prototype.$getUrlParms("pid"),'Vue.prototype.$getUrlParms("pid")');
  220. Vue.prototype.$bindid.getbindid({
  221. pid: Vue.prototype.$getUrlParms("pid")
  222. }, Vue.prototype.$store);
  223. // #endif
  224. Vue.prototype.$init_config(1);
  225. uni.setStorageSync('tabbar', null)
  226. const res = uni.getSystemInfoSync();
  227. if (res.platform == 'android') {
  228. Vue.prototype.platform = 1
  229. } else if (res.platform == 'ios') {
  230. Vue.prototype.platform = 2
  231. }
  232. //全局配置
  233. // #ifdef MP-WEIXIN
  234. Vue.mixin(mpShare)
  235. // #endif
  236. Vue.use(uView);
  237. const app = new Vue({
  238. ...App
  239. })
  240. app.$mount()
  241. }
  242. start();