main.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // #ifndef VUE3
  2. import Vue from 'vue'
  3. import App from './App'
  4. Vue.config.productionTip = false
  5. App.mpType = 'app'
  6. const app = new Vue({
  7. ...App
  8. })
  9. const api = {
  10. getSn() {
  11. return uni.getStorageSync("eq_sn");
  12. },
  13. setSn: function(sn) {
  14. sn = sn.split(",")[0]
  15. uni.setStorageSync("eq_sn", sn);
  16. },
  17. wsHost: function() {
  18. //WS地址
  19. // return "ws://192.168.31.75/websocket/";
  20. return "wss://ai.my-123.cn/websocket/";
  21. },
  22. apiHost: function() {
  23. //接口地址
  24. // return 'http://192.168.31.75/'
  25. return 'https://ai.my-123.cn/api/'
  26. },
  27. request: function(url, params, method,type,hideLoading) {
  28. //接口请求
  29. // if (!hideLoading) {
  30. // uni.showLoading({
  31. // mask: true,
  32. // title: '请稍候...'
  33. // })
  34. // }
  35. if(method==null||method==""){
  36. method="POST"
  37. }
  38. if(type==null||type==""){
  39. type='application/json'
  40. }
  41. return new Promise((resolve, reject) => {
  42. uni.request({
  43. url: this.apiHost() + url,
  44. data: params,
  45. header: {
  46. 'Authorization':'Basic d3hBcHBsZXQ6d3hBcHBsZXRfc2VjcmV0',
  47. 'tenant_id':'000000',
  48. 'content-type': type,
  49. },
  50. method: method,
  51. // dataType: 'json',
  52. success: (res) => {
  53. !hideLoading && uni.hideLoading()
  54. if (res.data.code == 200) { //访问成功
  55. resolve(res.data.data)
  56. }else if (res.data.code == 401) {
  57. uni.removeStorageSync("access_token")
  58. uni.removeStorageSync("user")
  59. // // #ifdef APP-PLUS || MP
  60. // this.deleteJYJPushAlias();
  61. // // #endif
  62. let url = '/pages/start/start?msg=' + (res.data.msg == undefined ? '' : res.data.msg)
  63. uni.navigateTo({
  64. url: url
  65. })
  66. }else {
  67. this.toast( res.data.msg == null ? "请求失败 , 请重试" : res.data.msg);
  68. reject(res)
  69. }
  70. },
  71. fail: (res) => {
  72. if (!hideLoading) {
  73. this.toast("网络不给力,请稍后再试~")
  74. }
  75. reject(res)
  76. }
  77. })
  78. })
  79. },
  80. toast: function(text, duration, success) {
  81. uni.showToast({
  82. title: text,
  83. icon: success ? 'success' : 'none',
  84. duration: duration || 2000
  85. })
  86. },
  87. formatTime:function(date, state) {
  88. if (!date) {
  89. date = new Date()
  90. }else{
  91. date = new Date(date)
  92. }
  93. let year = date.getFullYear()
  94. let month = date.getMonth() + 1
  95. let day = date.getDate()
  96. // const week = weekFormat(date.getDay())
  97. let hour = date.getHours()
  98. let minute = date.getMinutes()
  99. let second = date.getSeconds()
  100. let milliSecond = date.getMilliseconds()
  101. if(month<10){
  102. month="0"+month;
  103. }
  104. if(day<10){
  105. day="0"+day;
  106. }
  107. if(hour<10){
  108. hour="0"+hour;
  109. }
  110. if(minute<10){
  111. minute="0"+minute;
  112. }
  113. if(second<10){
  114. second="0"+second;
  115. }
  116. if (state == 'Y') {
  117. return year
  118. }
  119. if (state == 'YM') {
  120. return [year, month].join('-')
  121. }
  122. if (state == 'YMD') {
  123. return [year, month, day].join('-')
  124. }
  125. if (state == 'YMDHM') {
  126. return [year, month, day].join('-') + ' ' + [hour, minute].join(':')
  127. }
  128. if (state == 'HM') {
  129. return [hour, minute].join(':')
  130. }
  131. // if (state == 'MWHM') {
  132. // return [month, day].map(formatNumber).join('-') + ' ' + week + ' ' + [hour, minute].map(formatNumber).join(':')
  133. // }
  134. return [year, month, day].join('-')
  135. },
  136. getMacAddress:function(){
  137. var net = plus.android.importClass("java.net.NetworkInterface")
  138. var wl0 = net.getByName('wlan0')
  139. var macByte = wl0.getHardwareAddress()
  140. var str = ''
  141. for (var i = 0; i < macByte.length; i++) {
  142. var tmp = "";
  143. var num = macByte[i];
  144. if (num < 0) {
  145. tmp =(255+num+1).toString(16);
  146. } else {
  147. tmp = num.toString(16);
  148. }
  149. if (tmp.length == 1) {
  150. tmp = "0" + tmp;
  151. }
  152. if(i == macByte.length-1){
  153. str += tmp;
  154. }else{
  155. str = str + tmp;
  156. }
  157. }
  158. console.log('mac', str.toUpperCase())
  159. return str.toUpperCase()
  160. },
  161. }
  162. // // 引入请求封装
  163. // require('./util/request/index')(app)
  164. Vue.prototype.api = api
  165. app.$mount()
  166. // #endif
  167. // #ifdef VUE3
  168. import { createSSRApp } from 'vue'
  169. import App from './App.vue'
  170. export function createApp() {
  171. const app = createSSRApp(App)
  172. return {
  173. app
  174. }
  175. }
  176. // #endif