| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- // #ifndef VUE3
- import Vue from 'vue'
- import App from './App'
- Vue.config.productionTip = false
- App.mpType = 'app'
- const app = new Vue({
- ...App
- })
- const api = {
- getSn() {
- return uni.getStorageSync("eq_sn");
- },
- setSn: function(sn) {
- sn = sn.split(",")[0]
- uni.setStorageSync("eq_sn", sn);
- },
- wsHost: function() {
- //WS地址
- // return "ws://192.168.31.75/websocket/";
- return "wss://ai.my-123.cn/websocket/";
- },
- apiHost: function() {
- //接口地址
- // return 'http://192.168.31.75/'
- return 'https://ai.my-123.cn/api/'
- },
-
- request: function(url, params, method,type,hideLoading) {
- //接口请求
- // if (!hideLoading) {
- // uni.showLoading({
- // mask: true,
- // title: '请稍候...'
- // })
- // }
- if(method==null||method==""){
- method="POST"
- }
- if(type==null||type==""){
- type='application/json'
- }
- return new Promise((resolve, reject) => {
- uni.request({
- url: this.apiHost() + url,
- data: params,
- header: {
- 'Authorization':'Basic d3hBcHBsZXQ6d3hBcHBsZXRfc2VjcmV0',
- 'tenant_id':'000000',
- 'content-type': type,
- },
- method: method,
- // dataType: 'json',
- success: (res) => {
- !hideLoading && uni.hideLoading()
- if (res.data.code == 200) { //访问成功
- resolve(res.data.data)
- }else if (res.data.code == 401) {
- uni.removeStorageSync("access_token")
- uni.removeStorageSync("user")
- // // #ifdef APP-PLUS || MP
- // this.deleteJYJPushAlias();
- // // #endif
- let url = '/pages/start/start?msg=' + (res.data.msg == undefined ? '' : res.data.msg)
- uni.navigateTo({
- url: url
- })
- }else {
- this.toast( res.data.msg == null ? "请求失败 , 请重试" : res.data.msg);
- reject(res)
- }
- },
- fail: (res) => {
- if (!hideLoading) {
- this.toast("网络不给力,请稍后再试~")
- }
- reject(res)
- }
- })
- })
- },
- toast: function(text, duration, success) {
- uni.showToast({
- title: text,
- icon: success ? 'success' : 'none',
- duration: duration || 2000
- })
- },
- formatTime:function(date, state) {
- if (!date) {
- date = new Date()
- }else{
- date = new Date(date)
- }
- let year = date.getFullYear()
- let month = date.getMonth() + 1
- let day = date.getDate()
- // const week = weekFormat(date.getDay())
- let hour = date.getHours()
- let minute = date.getMinutes()
- let second = date.getSeconds()
- let milliSecond = date.getMilliseconds()
- if(month<10){
- month="0"+month;
- }
- if(day<10){
- day="0"+day;
- }
- if(hour<10){
- hour="0"+hour;
- }
- if(minute<10){
- minute="0"+minute;
- }
- if(second<10){
- second="0"+second;
- }
- if (state == 'Y') {
- return year
- }
- if (state == 'YM') {
- return [year, month].join('-')
- }
- if (state == 'YMD') {
- return [year, month, day].join('-')
- }
- if (state == 'YMDHM') {
- return [year, month, day].join('-') + ' ' + [hour, minute].join(':')
- }
- if (state == 'HM') {
- return [hour, minute].join(':')
- }
- // if (state == 'MWHM') {
- // return [month, day].map(formatNumber).join('-') + ' ' + week + ' ' + [hour, minute].map(formatNumber).join(':')
- // }
- return [year, month, day].join('-')
- },
- getMacAddress:function(){
- var net = plus.android.importClass("java.net.NetworkInterface")
- var wl0 = net.getByName('wlan0')
- var macByte = wl0.getHardwareAddress()
- var str = ''
- for (var i = 0; i < macByte.length; i++) {
- var tmp = "";
- var num = macByte[i];
- if (num < 0) {
- tmp =(255+num+1).toString(16);
- } else {
- tmp = num.toString(16);
- }
- if (tmp.length == 1) {
- tmp = "0" + tmp;
- }
- if(i == macByte.length-1){
- str += tmp;
- }else{
- str = str + tmp;
- }
- }
- console.log('mac', str.toUpperCase())
- return str.toUpperCase()
- },
- }
- // // 引入请求封装
- // require('./util/request/index')(app)
- Vue.prototype.api = api
- app.$mount()
- // #endif
- // #ifdef VUE3
- import { createSSRApp } from 'vue'
- import App from './App.vue'
- export function createApp() {
- const app = createSSRApp(App)
- return {
- app
- }
- }
- // #endif
|