main.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. import Vue from 'vue';
  2. import App from './App';
  3. // 引入全局存储
  4. import store from '@/store';
  5. // 引入全局配置
  6. import $mAssetsPath from '@/config/assets.config.js';
  7. import $mConfig from '@/config/index.config.js';
  8. import $mRoutesConfig from '@/config/routes.config.js';
  9. import $mFormRule from '@/config/formRule.config.js';
  10. import $mConstDataConfig from '@/config/constData.config.js';
  11. import $mSettingConfig from '@/config/setting.config.js';
  12. // 生产发布
  13. // Vue.prototype.websiteUrl = 'https://8.8.20.112:19001/api/file/pub/';
  14. // Vue.prototype.websiteUrl = 'https://m.geidcp.com/api/file/pub/';
  15. Vue.prototype.websiteUrl = 'https://m.geidcp.com/api/file/pub/';
  16. // Vue.prototype.websiteUrl = 'http://172.16.1.159:9100/api/fileextend/pub/';
  17. // Vue.prototype.websiteUrl = 'http://172.16.1.159:9100/api/file/pub/';
  18. // Vue.prototype.websiteUrl = 'http://192.168.95.118/api/file/pub/';
  19. // Vue.prototype.websiteUrl = 'https://www.geidcp.com/api/file/pub/';
  20. // Vue.prototype.websiteUrlExtend = 'https://8.8.20.112:19001/api/fileextend/pub/';
  21. // Vue.prototype.websiteUrl1 = 'https://8.8.20.112:19001/api/file';
  22. //h5本地调试
  23. // Vue.prototype.websiteUrl = 'http://localhost:8080/api/file/pub/';
  24. // Vue.prototype.websiteUrlExtend = 'http://localhost:8080/api/fileextend/pub/';
  25. // 160手机调试
  26. // Vue.prototype.websiteUrl = 'http://10.0.1.160:7000/file/pub/';
  27. // Vue.prototype.websiteUrlExtend = 'http://10.0.1.160:7000/fileextend/pub/';
  28. //生产发布图片上传地址
  29. Vue.prototype.uploadUrl = 'https://m.geidcp.com/api/meeting/upload/file/';
  30. // Vue.prototype.uploadUrl = 'https://8.8.20.112:19001/api/meeting/upload/file/';
  31. //h5本地图片上传地址
  32. // Vue.prototype.uploadUrl = 'http://localhost:8080/api/meeting/upload/file/';
  33. //160手机图片上传地址
  34. //Vue.prototype.uploadUrl = 'http://10.0.1.160:7000/meeting/upload/file/';
  35. // 引入全局方法
  36. import axios from 'axios'
  37. Vue.prototype.$http = axios
  38. axios.defaults.baseURL = 'http://localhost:7000'
  39. axios.defaults.baseURL = 'http://localhost:7000/api/uc/'
  40. import {
  41. myRequest
  42. } from './api/my-api.js'
  43. import commonArray from '@/static/js/common.js'
  44. Vue.use(commonArray)
  45. // 挂载到全局,让所有的页面都能调用myRequest方法
  46. Vue.prototype.$myRequest = myRequest
  47. import $mGraceChecker from '@/utils/graceChecker';
  48. import $mHelper from '@/utils/helper';
  49. import $mRouter from '@/utils/router';
  50. import $mPayment from '@/utils/payment';
  51. // 全局组件
  52. import rfImage from '@/components/rf-image/rf-image';
  53. import rfEmpty from '@/components/rf-empty';
  54. import rfLoading from '@/components/rf-loading';
  55. import rfLoadProgress from '@/components/rf-load-progress/rf-load-progress';
  56. import rfParser from '@/components/rf-parser';
  57. import rfBackTop from '@/components/rf-back-top';
  58. import rfTag from '@/components/rf-tag';
  59. import rfNavDetail from '@/components/rf-nav-detail';
  60. import cuCustom from '@/components/cu-custom';
  61. import rfBackHome from '@/components/rf-back-home';
  62. //全局属性
  63. Vue.prototype.systemInfo = uni.getSystemInfoSync();
  64. // 网络状态监听
  65. uni.getNetworkType({
  66. success: res => {
  67. store.dispatch('networkStateChange', res.networkType);
  68. }
  69. });
  70. // uni.onNetworkStatusChange(function (res) {
  71. // store.dispatch('networkStateChange', res.networkType);
  72. // });
  73. // 挂载全局自定义方法
  74. Vue.prototype.$mStore = store;
  75. import Json from './Json'; //测试用数据
  76. const json = type => {
  77. return new Promise(resolve => {
  78. setTimeout(() => {
  79. resolve(Json[type]);
  80. }, 100)
  81. })
  82. }
  83. const msg = (title, duration = 1500, mask = false, icon = 'none') => {
  84. //统一提示方便全局修改
  85. if (Boolean(title) === false) {
  86. return;
  87. }
  88. uni.showToast({
  89. title,
  90. duration,
  91. mask,
  92. icon
  93. });
  94. }
  95. const prePage = () => {
  96. let pages = getCurrentPages();
  97. let prePage = pages[pages.length - 2];
  98. // #ifdef H5
  99. return prePage;
  100. // #endif
  101. return prePage.$vm;
  102. }
  103. Vue.prototype.$api = {
  104. msg,
  105. json,
  106. prePage
  107. };
  108. // Vue.prototype.$http = http;
  109. Vue.prototype.$mConfig = $mConfig;
  110. Vue.prototype.$mAssetsPath = $mAssetsPath;
  111. Vue.prototype.$mFormRule = $mFormRule;
  112. Vue.prototype.$mRoutesConfig = $mRoutesConfig;
  113. Vue.prototype.$mConstDataConfig = $mConstDataConfig;
  114. Vue.prototype.$mSettingConfig = $mSettingConfig;
  115. Vue.prototype.$mGraceChecker = $mGraceChecker;
  116. Vue.prototype.$mHelper = $mHelper;
  117. Vue.prototype.$mRouter = $mRouter;
  118. Vue.prototype.$mPayment = $mPayment;
  119. Vue.component('rfImage', rfImage);
  120. Vue.component('rfEmpty', rfEmpty);
  121. Vue.component('rfLoading', rfLoading);
  122. Vue.component('rfLoadProgress', rfLoadProgress);
  123. Vue.component('rfParser', rfParser);
  124. Vue.component('rfBackTop', rfBackTop);
  125. Vue.component('rfTag', rfTag);
  126. Vue.component('rfNavDetail', rfNavDetail);
  127. Vue.component('cuCustom', cuCustom);
  128. Vue.component('rfBackHome', rfBackHome);
  129. if (process.env.NODE_ENV === 'production') {
  130. Vue.config.productionTip = false;
  131. }
  132. // 路由导航
  133. $mRouter.beforeEach((navType, to) => {
  134. if (to.route === undefined) {
  135. throw '路由钩子函数中没有找到to对象,路由信息:' + JSON.stringify(to);
  136. }
  137. if (to.route === $mRoutesConfig.login.path && store.getters.hasLogin) {
  138. uni.reLaunch({
  139. url: $mHelper.objParseUrlAndParam($mRoutesConfig.main.path)
  140. });
  141. return;
  142. }
  143. // 过滤需要权限的页面
  144. if (to.route.requiresAuth) {
  145. if (store.getters.hasLogin) {
  146. // 已经登录
  147. uni[navType]({
  148. url: $mHelper.objParseUrlAndParam(to.route.path, to.query)
  149. });
  150. } else {
  151. // 登录成功后的重定向地址和参数
  152. const query = {
  153. redirectUrl: to.route.path,
  154. ...to.query
  155. };
  156. // 没有登录 是否强制登录?
  157. if (store.state.forcedLogin) {
  158. uni.redirectTo({
  159. url: $mHelper.objParseUrlAndParam($mRoutesConfig.login.path, query)
  160. });
  161. } else {
  162. uni.navigateTo({
  163. url: $mHelper.objParseUrlAndParam($mRoutesConfig.login.path, query)
  164. });
  165. }
  166. }
  167. } else {
  168. uni[navType]({
  169. url: $mHelper.objParseUrlAndParam(to.route, to.query)
  170. });
  171. }
  172. });
  173. import i18n from './static/js/language/index'
  174. Vue.prototype._i18n = i18n
  175. import moment from "moment";
  176. Vue.prototype.moment = moment;
  177. import uView from "uview-ui";
  178. Vue.use(uView);
  179. Vue.prototype.formatDate = function(value, formatString, defaultString) {
  180. if (value == null) {
  181. return defaultString ? defaultString : "";
  182. }
  183. formatString = formatString || 'YYYY-MM-DD';
  184. return moment(value).format(formatString);
  185. }
  186. Vue.prototype.formatDateAndHouse = function(value, formatString, defaultString) {
  187. if (value == null) {
  188. return defaultString ? defaultString : "";
  189. }
  190. formatString = formatString || 'YYYY-MM-DD HH:mm:ss';
  191. return moment(value).format(formatString, "YYYY-MM-DD HH:mm:ss");
  192. }
  193. Vue.prototype.handlePublishTimeDesc = function(curTime, postModified, language) {
  194. // 计算两个时间戳
  195. const NewcurTime = moment(curTime).valueOf();
  196. const NewpostModified = moment(postModified).valueOf();
  197. const timeDiff = moment(NewcurTime).diff(moment(NewpostModified))
  198. // 单位换算
  199. var min = 60 * 1000;
  200. var hour = min * 60;
  201. var day = hour * 24;
  202. var week = day * 7;
  203. var month = week * 4;
  204. var year = month * 12;
  205. // 计算发布时间距离当前时间的周、天、时、分
  206. var exceedyear = Math.floor(timeDiff / year);
  207. var exceedmonth = Math.floor(timeDiff / month);
  208. var exceedWeek = Math.floor(timeDiff / week);
  209. var exceedDay = Math.floor(timeDiff / day);
  210. var exceedHour = Math.floor(timeDiff / hour);
  211. var exceedMin = Math.floor(timeDiff / min);
  212. // debugger;
  213. // 最后判断时间差到底是属于哪个区间,然后return
  214. if (exceedyear < 100 && exceedyear > 0) {
  215. return language == 'zh' ? exceedyear + '年前' : exceedyear + ' years ago';
  216. } else {
  217. if (exceedmonth < 12 && exceedmonth > 0) {
  218. return language == 'zh' ? exceedmonth + '月前' : exceedmonth + ' months ago';
  219. } else {
  220. if (exceedWeek < 4 && exceedWeek > 0) {
  221. return language == 'zh' ? exceedWeek + '星期前' : exceedWeek + ' weeks ago';
  222. } else {
  223. if (exceedDay < 7 && exceedDay > 0) {
  224. return language == 'zh' ? exceedDay + '天前' : exceedDay + ' days ago'
  225. } else {
  226. if (exceedHour < 24 && exceedHour > 0) {
  227. return language == 'zh' ? exceedHour + '小时前' : exceedHour + ' hours ago'
  228. } else {
  229. return language == 'zh' ? exceedMin + '分钟前' : exceedMin + ' minutes ago'
  230. }
  231. }
  232. }
  233. }
  234. }
  235. }
  236. App.mpType = 'app';
  237. Vue.mixin({
  238. computed: {
  239. themeColor: {
  240. get() {
  241. return store.getters.themeColor;
  242. },
  243. set(val) {
  244. store.state.themeColor = val;
  245. }
  246. }
  247. }
  248. });
  249. Vue.prototype.moneySymbol = $mConstDataConfig.moneySymbol;
  250. Vue.prototype.singleSkuText = $mConstDataConfig.singleSkuText;
  251. // 保留小数点后两位
  252. Vue.filter('keepTwoDecimal', value => {
  253. return (Math.floor((value || 0) * 100) / 100).toFixed(2);
  254. });
  255. const app = new Vue({
  256. ...App,
  257. i18n,
  258. store: store
  259. });
  260. app.$mount();