main.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. import App from './App'
  2. // #ifndef VUE3
  3. import Vue from 'vue'
  4. Vue.config.productionTip = false
  5. App.mpType = 'app'
  6. const app = new Vue({
  7. ...App
  8. })
  9. //注册uView组件
  10. import uView from 'uview-ui';
  11. Vue.use(uView);
  12. app.$mount()
  13. // #endif
  14. // #ifdef VUE3
  15. import {
  16. createSSRApp
  17. } from 'vue'
  18. export function createApp() {
  19. const app = createSSRApp(App)
  20. return {
  21. app
  22. }
  23. }
  24. // #endif
  25. let baseUrl = "http://localhost:8201/hxds-customer"
  26. Vue.prototype.url = {
  27. registerNewCustomer: `${baseUrl}/customer/registerNewCustomer`,
  28. login: `${baseUrl}/customer/login`,
  29. insertCustomerCar: `${baseUrl}/customer/car/insertCustomerCar`,
  30. searchCustomerCarList: `${baseUrl}/customer/car/searchCustomerCarList`,
  31. deleteCustomerCarById: `${baseUrl}/customer/car/deleteCustomerCarById`,
  32. createNewOrder: `${baseUrl}/order/createNewOrder`,
  33. searchOrderStatus: `${baseUrl}/order/searchOrderStatus`,
  34. deleteUnAcceptOrder: `${baseUrl}/order/deleteUnAcceptOrder`,
  35. hasCustomerCurrentOrder: `${baseUrl}/order/hasCustomerCurrentOrder`,
  36. searchOrderForMoveById: `${baseUrl}/order/searchOrderForMoveById`,
  37. searchOrderLocationCache: `${baseUrl}/order/location/searchOrderLocationCache`,
  38. confirmArriveStartPlace: `${baseUrl}/order/confirmArriveStartPlace`,
  39. receiveBillMessage: `${baseUrl}/message/receiveBillMessage`,
  40. searchOrderById: `${baseUrl}/order/searchOrderById`,
  41. createWxPayment: `${baseUrl}/order/createWxPayment`,
  42. updateOrderAboutPayment: `${baseUrl}/order/updateOrderAboutPayment`,
  43. insertComment: `${baseUrl}/comment/insertComment`,
  44. searchCustomerOrderByPage: `${baseUrl}/order/searchCustomerOrderByPage`,
  45. searchUnTakeVoucherByPage: `${baseUrl}/voucher/searchUnTakeVoucherByPage`,
  46. searchUnUseVoucherByPage: `${baseUrl}/voucher/searchUnUseVoucherByPage`,
  47. searchUsedVoucherByPage: `${baseUrl}/voucher/searchUsedVoucherByPage`,
  48. searchUnUseVoucherCount: `${baseUrl}/voucher/searchUnUseVoucherCount`,
  49. takeVoucher: `${baseUrl}/voucher/takeVoucher`,
  50. }
  51. Vue.prototype.tencent = {
  52. map: {
  53. referer: "华星代驾",
  54. key: "4WRBZ-SVM3Z-WKAXG-7SU6N-52ESO-E6BRU"
  55. }
  56. }
  57. Vue.prototype.ajax = function(url, method, data, fun, load) {
  58. let timer = null
  59. if (load == true || load == undefined) {
  60. uni.showLoading({
  61. title: "执行中"
  62. })
  63. timer = setTimeout(function() {
  64. uni.hideLoading()
  65. }, 60 * 1000)
  66. }
  67. uni.request({
  68. "url": url,
  69. "method": method,
  70. "header": {
  71. token: uni.getStorageSync("token")
  72. },
  73. "data": data,
  74. success: function(resp) {
  75. if (load == true || load == undefined) {
  76. clearTimeout(timer)
  77. uni.hideLoading()
  78. }
  79. if (resp.statusCode == 401) {
  80. uni.redirectTo({
  81. url: "/pages/login/login.vue"
  82. })
  83. } else if (resp.statusCode == 200 && resp.data.code == 200) {
  84. let data = resp.data
  85. if (data.hasOwnProperty("token")) {
  86. let token = data.token
  87. uni.setStorageSync("token", token)
  88. }
  89. fun(resp)
  90. } else {
  91. uni.showToast({
  92. icon: "none",
  93. title: "执行异常"
  94. })
  95. console.error(resp.data)
  96. }
  97. },
  98. fail: function(error) {
  99. if (load == true || load == undefined) {
  100. clearTimeout(timer)
  101. uni.hideLoading()
  102. }
  103. }
  104. })
  105. }
  106. Vue.prototype.refreshMessage = function(that) {
  107. uni.request({
  108. "url": that.url.refreshMessage,
  109. "method": "POST",
  110. "header": {
  111. token: uni.getStorageSync("token")
  112. },
  113. "data": {
  114. identity: 'driver'
  115. },
  116. success: function(resp) {
  117. if (resp.statusCode == 401) {
  118. uni.redirectTo({
  119. url: "/pages/login/login.vue"
  120. })
  121. } else if (resp.statusCode == 200 && resp.data.code == 200) {
  122. uni.$emit("updateMessageService", true)
  123. let result = resp.data.result
  124. let lastRows = result.lastRows
  125. let unreadRows = result.unreadRows
  126. if (lastRows > 0) {
  127. uni.$emit("showMessageTip", lastRows)
  128. }
  129. } else {
  130. console.error(resp.data)
  131. //在工作台页面触发更新消息服务状态,显示服务可用或者不可用
  132. uni.$emit("updateMessageService", false)
  133. }
  134. console.log("刷新消息")
  135. },
  136. fail: function(error) {
  137. //在工作台页面触发更新消息服务状态,显示服务可用或者不可用
  138. uni.$emit("updateMessageService", false)
  139. }
  140. })
  141. }
  142. Vue.prototype.uploadCos = function(url, path, module, fun) {
  143. uni.uploadFile({
  144. url: url,
  145. filePath: path,
  146. name: "file",
  147. header: {
  148. token: uni.getStorageSync("token")
  149. },
  150. formData: {
  151. "module": module
  152. },
  153. success: function(resp) {
  154. let data = JSON.parse(resp.data)
  155. if (resp.statusCode == 401) {
  156. uni.redirectTo({
  157. url: "/pages/login/login.vue"
  158. })
  159. } else if (resp.statusCode == 200 && data.code == 200) {
  160. fun(resp)
  161. } else {
  162. uni.showToast({
  163. icon: "none",
  164. title: data.error
  165. })
  166. }
  167. }
  168. })
  169. }
  170. Vue.prototype.upload = function(url, path, data, fun) {
  171. uni.uploadFile({
  172. url: url,
  173. filePath: path,
  174. name: "file",
  175. header: {
  176. token: uni.getStorageSync("token")
  177. },
  178. formData: data,
  179. success: function(resp) {
  180. let data = JSON.parse(resp.data)
  181. if (resp.statusCode == 401) {
  182. uni.redirectTo({
  183. url: "/pages/login/login.vue"
  184. })
  185. } else if (resp.statusCode == 200 && data.code == 200) {
  186. fun(resp)
  187. } else {
  188. uni.showToast({
  189. icon: "none",
  190. title: data.error
  191. })
  192. }
  193. }
  194. })
  195. }
  196. Vue.prototype.toPage = function(url) {
  197. uni.navigateTo({
  198. url: url
  199. })
  200. }
  201. Vue.prototype.checkNull = function(data, name) {
  202. if (data == null) {
  203. this.$refs.uToast.show({
  204. title: name + "不能为空",
  205. type: 'error'
  206. })
  207. return true
  208. }
  209. return false
  210. }
  211. Vue.prototype.checkBlank = function(data, name) {
  212. if (data == null || data == "") {
  213. this.$refs.uToast.show({
  214. title: name + "不能为空",
  215. type: 'error'
  216. })
  217. return true
  218. }
  219. return false
  220. }
  221. Vue.prototype.checkValidName = function(data, name) {
  222. if (data == null || data == "") {
  223. this.$refs.uToast.show({
  224. title: name + "不能为空",
  225. type: 'error'
  226. })
  227. return false
  228. } else if (!/^[\u4e00-\u9fa5]{2,15}$/.test(data)) {
  229. this.$refs.uToast.show({
  230. title: name + "不正确",
  231. type: 'error'
  232. })
  233. return false
  234. }
  235. return true
  236. }
  237. Vue.prototype.checkValidTel = function(data, name) {
  238. if (data == null || data == "") {
  239. this.$refs.uToast.show({
  240. title: name + "不能为空",
  241. type: 'error'
  242. })
  243. return false
  244. } else if (!/^1[0-9]{10}$/.test(data)) {
  245. this.$refs.uToast.show({
  246. title: name + "不正确",
  247. type: 'error'
  248. })
  249. return false
  250. }
  251. return true
  252. }
  253. Vue.prototype.checkValidEmail = function(data, name) {
  254. if (data == null || data == "") {
  255. this.$refs.uToast.show({
  256. title: name + "不能为空",
  257. type: 'error'
  258. })
  259. return false
  260. } else if (!/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(data)) {
  261. this.$refs.uToast.show({
  262. title: name + "不正确",
  263. type: 'error'
  264. })
  265. return false
  266. }
  267. return true
  268. }
  269. Vue.prototype.checkValidAddress = function(data, name) {
  270. if (data == null || data == "") {
  271. this.$refs.uToast.show({
  272. title: name + "不能为空",
  273. type: 'error'
  274. })
  275. return false
  276. } else if (!/^[0-9a-zA-Z\u4e00-\u9fa5\-]{6,50}$/.test(data)) {
  277. this.$refs.uToast.show({
  278. title: name + "不正确",
  279. type: 'error'
  280. })
  281. return false
  282. }
  283. return true
  284. }
  285. Vue.prototype.checkValidFee = function(data, name) {
  286. if (data == null || data == "") {
  287. this.$refs.uToast.show({
  288. title: name + "不能为空",
  289. type: 'error'
  290. })
  291. return false
  292. } else if (!/^[1-9]\d*\.\d{1,2}$|^0\.\d{1,2}$|^[1-9]\d*$/.test(data)) {
  293. this.$refs.uToast.show({
  294. title: name + "不正确",
  295. type: 'error'
  296. })
  297. return false
  298. }
  299. return true
  300. }
  301. Vue.prototype.checkValidCarType = function(data, name) {
  302. if (data == null || data == "") {
  303. this.$refs.uToast.show({
  304. title: name + "不能为空",
  305. type: 'error'
  306. })
  307. return false
  308. } else if (!/^[\u4e00-\u9fa5A-Za-z0-9\-\_\s]{2,20}$/.test(data)) {
  309. this.$refs.uToast.show({
  310. title: name + "不正确",
  311. type: 'error'
  312. })
  313. return false
  314. }
  315. return true
  316. }
  317. Vue.prototype.checkValidCarPlate = function(data, name) {
  318. if (data == null || data == "") {
  319. this.$refs.uToast.show({
  320. title: name + "不能为空",
  321. type: 'error'
  322. })
  323. return false
  324. } else if (!
  325. /^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1})$/
  326. .test(data)) {
  327. this.$refs.uToast.show({
  328. title: name + "不正确",
  329. type: 'error'
  330. })
  331. return false
  332. }
  333. return true
  334. }
  335. Vue.prototype.changeNumber = function(value) {
  336. let newValue = ['', ''];
  337. let fr = 1000;
  338. const ad = 1;
  339. let num = 3;
  340. const fm = 1;
  341. while (value / fr >= 1) {
  342. fr *= 10;
  343. num += 1;
  344. }
  345. if (num <= 4) {
  346. // 千
  347. newValue[1] = '千';
  348. newValue[0] = parseInt(value / 1000) + '';
  349. } else if (num <= 8) {
  350. // 万
  351. const text1 = parseInt(num - 4) / 3 > 1 ? '千万' : '万';
  352. const fm = '万' === text1 ? 10000 : 10000000;
  353. newValue[1] = text1;
  354. newValue[0] = value / fm + '';
  355. } else if (num <= 16) {
  356. // 亿
  357. let text1 = (num - 8) / 3 > 1 ? '千亿' : '亿';
  358. text1 = (num - 8) / 4 > 1 ? '万亿' : text1;
  359. text1 = (num - 8) / 7 > 1 ? '千万亿' : text1;
  360. // tslint:disable-next-line:no-shadowed-variable
  361. let fm = 1;
  362. if ('亿' === text1) {
  363. fm = 100000000;
  364. } else if ('千亿' === text1) {
  365. fm = 100000000000;
  366. } else if ('万亿' === text1) {
  367. fm = 1000000000000;
  368. } else if ('千万亿' === text1) {
  369. fm = 1000000000000000;
  370. }
  371. newValue[1] = text1;
  372. newValue[0] = parseInt(value / fm) + '';
  373. }
  374. if (value < 1000) {
  375. newValue[1] = '';
  376. newValue[0] = value + '';
  377. }
  378. let temp = Math.floor((newValue[0]) * 100) / 100
  379. return temp + newValue[1];
  380. }