main.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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://10.114.41.214:8201/hxds-driver"
  26. Vue.prototype.url = {
  27. registerNewDriver: `${baseUrl}/driver/registerNewDriver`,
  28. updateDriverAuth: `${baseUrl}/driver/updateDriverAuth`,
  29. uploadCosPrivateFile: `${baseUrl}/cos/uploadCosPrivateFile`,
  30. deleteCosPrivateFile: `${baseUrl}/cos/deleteCosPrivateFile`,
  31. createDriverFaceModel: `${baseUrl}/driver/createDriverFaceModel`,
  32. verificateDriverFace: `${baseUrl}/driver/recognition/verificateDriverFace`,
  33. login: `${baseUrl}/driver/login`,
  34. logout: `${baseUrl}/driver/logout`,
  35. searchDriverBaseInfo: `${baseUrl}/driver/searchDriverBaseInfo`,
  36. searchWorkbenchData: `${baseUrl}/driver/searchWorkbenchData`,
  37. searchDriverAuth: `${baseUrl}/driver/searchDriverAuth`,
  38. startWork: `${baseUrl}/driver/startWork`,
  39. stopWork: `${baseUrl}/driver/stopWork`,
  40. receiveNewOrderMessage: `${baseUrl}/message/order/new/receiveNewOrderMessage`,
  41. acceptNewOrder: `${baseUrl}/order/acceptNewOrder`,
  42. searchDriverExecuteOrder: `${baseUrl}/order/searchDriverExecuteOrder`,
  43. searchDriverCurrentOrder: `${baseUrl}/order/searchDriverCurrentOrder`,
  44. searchOrderForMoveById: `${baseUrl}/order/searchOrderForMoveById`,
  45. arriveStartPlace: `${baseUrl}/order/arriveStartPlace`,
  46. startDriving: `${baseUrl}/order/startDriving`,
  47. uploadRecordFile: `${baseUrl}/monitoring/uploadRecordFile`,
  48. updateOrderStatus: `${baseUrl}/order/updateOrderStatus`,
  49. updateBillFee: `${baseUrl}/order/updateBillFee`,
  50. searchReviewDriverOrderBill: `${baseUrl}/order/searchReviewDriverOrderBill`,
  51. searchOrderStatus: `${baseUrl}/order/searchOrderStatus`,
  52. updateOrderAboutPayment: `${baseUrl}/order/updateOrderAboutPayment`,
  53. searchDriverOrderByPage: `${baseUrl}/order/searchDriverOrderByPage`,
  54. searchOrderById: `${baseUrl}/order/searchOrderById`,
  55. startCommentWorkflow: `${baseUrl}/comment/startCommentWorkflow`,
  56. }
  57. Vue.prototype.tencent = {
  58. map: {
  59. referer: "华星代驾",
  60. key: "4WRBZ-SVM3Z-WKAXG-7SU6N-52ESO-E6BRU"
  61. }
  62. }
  63. Vue.prototype.ajax = function(url, method, data, fun, load) {
  64. let timer = null
  65. if (load == true || load == undefined) {
  66. uni.showLoading({
  67. title: "执行中"
  68. })
  69. timer = setTimeout(function() {
  70. uni.hideLoading()
  71. }, 60 * 1000)
  72. }
  73. uni.request({
  74. "url": url,
  75. "method": method,
  76. "header": {
  77. token: uni.getStorageSync("token")
  78. },
  79. "data": data,
  80. success: function(resp) {
  81. // console.log(resp)
  82. if (load == true || load == undefined) {
  83. clearTimeout(timer)
  84. uni.hideLoading()
  85. }
  86. if (resp.statusCode == 401) {
  87. uni.redirectTo({
  88. url: "/pages/login/login.vue"
  89. })
  90. } else if (resp.statusCode == 200 && resp.data.code == 200) {
  91. let data = resp.data
  92. if (data.hasOwnProperty("token")) {
  93. let token = data.token
  94. uni.setStorageSync("token", token)
  95. }
  96. fun(resp)
  97. } else if (resp.data.error == "该微信无法注册") {
  98. uni.showToast({
  99. icon: "none",
  100. title: "该微信无法注册"
  101. })
  102. } else if (resp.data.error == "当前手机号与注册手机号不一致") {
  103. uni.showToast({
  104. icon: "none",
  105. title: "当前手机号与注册手机号不一致"
  106. })
  107. } else {
  108. uni.showToast({
  109. icon: "none",
  110. title: "执行异常"
  111. })
  112. console.error(resp.data)
  113. }
  114. },
  115. fail: function(error) {
  116. if (load == true || load == undefined) {
  117. clearTimeout(timer)
  118. uni.hideLoading()
  119. }
  120. }
  121. })
  122. }
  123. Vue.prototype.refreshMessage = function(that) {
  124. uni.request({
  125. "url": that.url.refreshMessage,
  126. "method": "POST",
  127. "header": {
  128. token: uni.getStorageSync("token")
  129. },
  130. "data": {
  131. identity: 'driver'
  132. },
  133. success: function(resp) {
  134. if (resp.statusCode == 401) {
  135. uni.redirectTo({
  136. url: "/pages/login/login.vue"
  137. })
  138. } else if (resp.statusCode == 200 && resp.data.code == 200) {
  139. uni.$emit("updateMessageService", true)
  140. let result = resp.data.result
  141. let lastRows = result.lastRows
  142. let unreadRows = result.unreadRows
  143. if (lastRows > 0) {
  144. uni.$emit("showMessageTip", lastRows)
  145. }
  146. } else {
  147. console.error(resp.data)
  148. //在工作台页面触发更新消息服务状态,显示服务可用或者不可用
  149. uni.$emit("updateMessageService", false)
  150. }
  151. console.log("刷新消息")
  152. },
  153. fail: function(error) {
  154. //在工作台页面触发更新消息服务状态,显示服务可用或者不可用
  155. uni.$emit("updateMessageService", false)
  156. }
  157. })
  158. }
  159. Vue.prototype.uploadCos = function(url, path, module, fun) {
  160. uni.uploadFile({
  161. url: url,
  162. filePath: path,
  163. name: "file",
  164. header: {
  165. token: uni.getStorageSync("token")
  166. },
  167. formData: {
  168. "module": module
  169. },
  170. success: function(resp) {
  171. let data = JSON.parse(resp.data)
  172. if (resp.statusCode == 401) {
  173. uni.redirectTo({
  174. url: "/pages/login/login.vue"
  175. })
  176. } else if (resp.statusCode == 200 && data.code == 200) {
  177. fun(resp)
  178. } else {
  179. uni.showToast({
  180. icon: "none",
  181. title: data.error
  182. })
  183. }
  184. }
  185. })
  186. }
  187. Vue.prototype.upload = function(url, path, data, fun) {
  188. uni.uploadFile({
  189. url: url,
  190. filePath: path,
  191. name: "file",
  192. header: {
  193. token: uni.getStorageSync("token")
  194. },
  195. formData: data,
  196. success: function(resp) {
  197. let data = JSON.parse(resp.data)
  198. if (resp.statusCode == 401) {
  199. uni.redirectTo({
  200. url: "/pages/login/login.vue"
  201. })
  202. } else if (resp.statusCode == 200 && data.code == 200) {
  203. fun(resp)
  204. } else {
  205. uni.showToast({
  206. icon: "none",
  207. title: data.error
  208. })
  209. }
  210. },
  211. fail: function(error) {
  212. console.log(error)
  213. }
  214. })
  215. }
  216. Vue.prototype.toPage = function(url) {
  217. uni.navigateTo({
  218. url: url
  219. })
  220. }
  221. Vue.prototype.checkNull = function(data, name) {
  222. if (data == null) {
  223. this.$refs.uToast.show({
  224. title: name + "不能为空",
  225. type: 'error'
  226. })
  227. return true
  228. }
  229. return false
  230. }
  231. Vue.prototype.checkBlank = function(data, name) {
  232. if (data == null || data == "") {
  233. this.$refs.uToast.show({
  234. title: name + "不能为空",
  235. type: 'error'
  236. })
  237. return true
  238. }
  239. return false
  240. }
  241. Vue.prototype.checkValidName = function(data, name) {
  242. if (data == null || data == "") {
  243. this.$refs.uToast.show({
  244. title: name + "不能为空",
  245. type: 'error'
  246. })
  247. return false
  248. } else if (!/^[\u4e00-\u9fa5]{2,15}$/.test(data)) {
  249. this.$refs.uToast.show({
  250. title: name + "不正确",
  251. type: 'error'
  252. })
  253. return false
  254. }
  255. return true
  256. }
  257. Vue.prototype.checkValidTel = function(data, name) {
  258. if (data == null || data == "") {
  259. this.$refs.uToast.show({
  260. title: name + "不能为空",
  261. type: 'error'
  262. })
  263. return false
  264. } else if (!/^1[0-9]{10}$/.test(data)) {
  265. this.$refs.uToast.show({
  266. title: name + "不正确",
  267. type: 'error'
  268. })
  269. return false
  270. }
  271. return true
  272. }
  273. Vue.prototype.checkValidEmail = function(data, name) {
  274. if (data == null || data == "") {
  275. this.$refs.uToast.show({
  276. title: name + "不能为空",
  277. type: 'error'
  278. })
  279. return false
  280. } else if (!/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(data)) {
  281. this.$refs.uToast.show({
  282. title: name + "不正确",
  283. type: 'error'
  284. })
  285. return false
  286. }
  287. return true
  288. }
  289. Vue.prototype.checkValidAddress = function(data, name) {
  290. if (data == null || data == "") {
  291. this.$refs.uToast.show({
  292. title: name + "不能为空",
  293. type: 'error'
  294. })
  295. return false
  296. } else if (!/^[0-9a-zA-Z\u4e00-\u9fa5\-]{6,50}$/.test(data)) {
  297. this.$refs.uToast.show({
  298. title: name + "不正确",
  299. type: 'error'
  300. })
  301. return false
  302. }
  303. return true
  304. }
  305. Vue.prototype.checkValidFee = function(data, name) {
  306. if (data == null || data == "") {
  307. this.$refs.uToast.show({
  308. title: name + "不能为空",
  309. type: 'error'
  310. })
  311. return false
  312. } else if (!/^[1-9]\d*\.\d{1,2}$|^0\.\d{1,2}$|^[1-9]\d*$/.test(data)) {
  313. this.$refs.uToast.show({
  314. title: name + "不正确",
  315. type: 'error'
  316. })
  317. return false
  318. }
  319. return true
  320. }
  321. Vue.prototype.changeNumber = function(value) {
  322. let newValue = ['', ''];
  323. let fr = 1000;
  324. const ad = 1;
  325. let num = 3;
  326. const fm = 1;
  327. while (value / fr >= 1) {
  328. fr *= 10;
  329. num += 1;
  330. }
  331. if (num <= 4) {
  332. // 千
  333. newValue[1] = '千';
  334. newValue[0] = parseInt(value / 1000) + '';
  335. } else if (num <= 8) {
  336. // 万
  337. const text1 = parseInt(num - 4) / 3 > 1 ? '千万' : '万';
  338. const fm = '万' === text1 ? 10000 : 10000000;
  339. newValue[1] = text1;
  340. newValue[0] = value / fm + '';
  341. } else if (num <= 16) {
  342. // 亿
  343. let text1 = (num - 8) / 3 > 1 ? '千亿' : '亿';
  344. text1 = (num - 8) / 4 > 1 ? '万亿' : text1;
  345. text1 = (num - 8) / 7 > 1 ? '千万亿' : text1;
  346. // tslint:disable-next-line:no-shadowed-variable
  347. let fm = 1;
  348. if ('亿' === text1) {
  349. fm = 100000000;
  350. } else if ('千亿' === text1) {
  351. fm = 100000000000;
  352. } else if ('万亿' === text1) {
  353. fm = 1000000000000;
  354. } else if ('千万亿' === text1) {
  355. fm = 1000000000000000;
  356. }
  357. newValue[1] = text1;
  358. newValue[0] = parseInt(value / fm) + '';
  359. }
  360. if (value < 1000) {
  361. newValue[1] = '';
  362. newValue[0] = value + '';
  363. }
  364. let temp = Math.floor((newValue[0]) * 100) / 100
  365. return temp + newValue[1];
  366. }