main.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import Vue from 'vue'
  2. import App from './App'
  3. Vue.config.productionTip = false
  4. Vue.prototype.$BASE_URL = "" //接口路径,结尾不带“/”,如:https://pickup.tkkab.com
  5. Vue.prototype.$ANNEX_URL = "" //图片资源路径,结尾不带“/”,如:https://pickup.tkkab.com
  6. //复制粘贴的功能
  7. Vue.prototype.$PIC = function(picUrl) {
  8. if (picUrl.indexOf('https://') == -1 && picUrl.indexOf('http://') == -1&& picUrl.indexOf('//') == -1) {
  9. picUrl = this.$ANNEX_URL + picUrl;
  10. }
  11. return picUrl;
  12. }
  13. // get请求方法
  14. Vue.prototype.$GET_FUN = function(url, data, Success, Fail) {
  15. if (url.indexOf('https://') == -1 && url.indexOf('http://') == -1) {
  16. url = this.$BASE_URL + url;
  17. }
  18. let TOKEN=uni.getStorageSync("token");
  19. //console.log(TOKEN);
  20. uni.request({
  21. url: url, //接口地址
  22. data: data, //传入的数据
  23. method: "GET",
  24. dataType: "json",
  25. header: {
  26. 'content-type': 'multipart/form-data' ,//自定义请求头信息
  27. 'Accept': 'application/json, text/javascript, ' ,//自定义请求头信息
  28. 'X-Requested-With': 'XMLHttpRequest' ,//自定义请求头信息
  29. 'token':TOKEN,
  30. },
  31. success: (res,statusCode,header,cookies) => {
  32. if (typeof Success === "function") {
  33. Success(res)
  34. }
  35. },
  36. fail: (errMsg) => {
  37. if (typeof Fail === "function") {
  38. Fail(errMsg)
  39. }
  40. }
  41. });
  42. }
  43. // post请求方法
  44. Vue.prototype.$POST_FUN = function(url, data, Success, Fail) {
  45. if (url.indexOf('https://') == -1 && url.indexOf('http://') == -1) {
  46. url = this.$BASE_URL + url;
  47. }
  48. let TOKEN=uni.getStorageSync("token");
  49. uni.request({
  50. url: url, //接口地址
  51. data: data, //传入的数据
  52. method: "POST",
  53. dataType: "json",
  54. header: {
  55. 'content-type': 'application/x-www-form-urlencoded' ,//自定义请求头信息
  56. 'token':TOKEN,
  57. },
  58. success: (res,statusCode,header,cookies) => {
  59. if (typeof Success === "function") {
  60. Success(res)
  61. }
  62. },
  63. fail: (errMsg) => {
  64. if (typeof Fail === "function") {
  65. Fail(errMsg)
  66. }
  67. uni.getNetworkType({
  68. success: function(res) {
  69. console.log(res.networkType);
  70. if (res.networkType == 'none') {
  71. uni.showToast({
  72. title: "请检查网络",
  73. icon: "none"
  74. })
  75. }
  76. }
  77. });
  78. }
  79. });
  80. }
  81. App.mpType = 'app'
  82. const app = new Vue({
  83. ...App
  84. })
  85. app.$mount()