<template>
|
<!-- <u-card :title="你好"> -->
|
|
<view class="" slot="body">
|
<!-- <view v-for="(item,index) in tree" :key="item.id"> -->
|
<template>
|
<view style="display: flex;height:50px;">
|
<button
|
:style="{borderRadius: '50%',width: '35px',height: '35px',margin: '5px',backgroundColor: online ? 'green' : 'red'}"></button>
|
<div style="margin:10px;">{{online?'在线':'离线'}}</div>
|
<u-switch v-model="value" @change="asyncChange" style="margin-left: 180px;margin-top: 10px;"></u-switch>
|
<text style="margin-left: 10px;margin-top: 15px;">{{ value ? '自动模式' : '手动模式' }}</text>
|
</view>
|
</template>
|
<u-grid :col="3">
|
<u-grid-item @tap="clickCoupon(item.url)" v-for="(item) in tree" :key="item.id">
|
<u-icon name="coupon" :size="50"></u-icon>
|
<view class="grid-text">{{item.name}}</view>
|
</u-grid-item>
|
</u-grid>
|
<!-- </view> -->
|
<u-toast ref="uToast" />
|
</view>
|
|
<!-- </u-card> -->
|
</template>
|
|
<script>
|
import {
|
config
|
} from '../../common/config.js'
|
export default {
|
data() {
|
return {
|
// title: '操作功能'
|
datas: [],
|
tree: [],
|
version: "",
|
online: false,
|
value: false,
|
isChanging: false
|
}
|
},
|
onShow() {
|
uni.getSystemInfo({
|
success: (res) => {
|
this.version = res.appWgtVersion;
|
// console.log(res);
|
//检测当前平台,如果是安卓则启动安卓更新
|
if (res.platform == "android") {
|
this.AndroidCheckUpdate();
|
}
|
}
|
});
|
|
},
|
onLoad() {
|
this.getCurrentTree();
|
this.Socketonline();
|
this.GetAutoStatus();
|
},
|
beforeDestroy() {
|
if (this.intervalId) {
|
clearInterval(this.intervalId);
|
}
|
},
|
mounted() {
|
this.Socketonline();
|
this.GetAutoStatus();
|
setInterval(() => {
|
this.Socketonline();
|
this.GetAutoStatus();
|
}, 5000);
|
|
var print = uni.getStorageSync('printFloor');
|
if (print) {
|
config.printFloor = print;;
|
}
|
|
var outbound = uni.getStorageSync('outboundFloor');
|
if (outbound) {
|
config.outboundFloor = outbound;
|
}
|
},
|
|
methods: {
|
asyncChange(e) {
|
if (this.isChanging) return;
|
this.isChanging = true;
|
|
|
// 先显示loading状态
|
this.$refs.uToast.show({
|
title: '正在切换模式...',
|
type: 'loading',
|
duration: 1000
|
});
|
|
// var param = {
|
// MainData: {
|
// "auto": e ? 'true' : 'false' // 直接使用传入的e值
|
// },
|
// }
|
// console.log(param);
|
this.$u.post('/api/PDA/AutoStatus?auto='+( e ? 'true' : 'false'), {}).then(result => {
|
console.log(result);
|
if (result) {
|
this.value = e; // 只有在请求成功后才更新实际值
|
this.switchValue = e; // 同步switch的状态
|
this.$refs.uToast.show({
|
title: '模式切换成功',
|
type: 'success',
|
duration: 1000
|
});
|
} else {
|
this.switchValue = !e; // 请求失败则恢复switch状态
|
this.$refs.uToast.show({
|
title: '模式切换失败',
|
type: 'error',
|
duration: 1000
|
});
|
}
|
}).catch(error => {
|
this.switchValue = !e; // 请求失败则恢复switch状态
|
this.$refs.uToast.show({
|
title: '请求出错',
|
type: 'error',
|
duration: 1000
|
});
|
}).finally(() => {
|
this.isChanging = false;
|
});
|
},
|
AndroidCheckUpdate: function() {
|
var _this = this;
|
uni.request({
|
url: 'http://192.168.30.250:5000/api/PDA/GetPDAVersion?version=' + this.version,
|
method: 'GET',
|
data: {},
|
success: res => {
|
if (res.data.data) {
|
|
uni.showToast({
|
title: '有新的版本发布,检测到您目前为Wifi连接,程序已启动自动更新。新版本下载完成后将自动弹出安装程序。',
|
mask: false,
|
duration: 5000,
|
icon: "none"
|
});
|
var dtask = plus.downloader.createDownload(
|
"http://192.168.30.250:5000/api/PDA/DownLoadApp", {},
|
function(d, status) {
|
// 下载完成
|
if (status == 200) {
|
plus.runtime.install(plus.io.convertLocalFileSystemURL(d
|
.filename), {}, {}, function(error) {
|
uni.showToast({
|
title: '安装失败',
|
mask: false,
|
duration: 1500
|
});
|
})
|
} else {
|
uni.showToast({
|
title: '更新失败',
|
mask: false,
|
duration: 1500
|
});
|
}
|
});
|
dtask.start();
|
}
|
},
|
fail: () => {
|
console.log('请求失败')
|
},
|
complete: () => {}
|
});
|
},
|
getCurrentTree() {
|
this.$u.post('/api/Menu/getTreeMenu', {}).then(result => {
|
this.tree = result;
|
})
|
},
|
GetAutoStatus() {
|
this.$u.post('/api/PDA/GetAutoStatus', {}).then(result => {
|
if (result == false) {
|
this.value = false;
|
} else {
|
this.value = true;
|
}
|
}).catch(error => {
|
this.value = false;
|
});
|
},
|
Socketonline() {
|
this.$u.post('/api/PDA/Socketonline', {}).then(result => {
|
if (result.data != null && result.data == false) {
|
console.log(result);
|
this.online = false;
|
} else {
|
this.online = true;
|
}
|
// = result;
|
}).catch(error => {
|
this.online = false;
|
});
|
},
|
getTree(id, data, isRootId) {
|
this.datas.forEach((x) => {
|
if (x.pid == id) {
|
x.lv = data.lv + 1;
|
if (isRootId) {
|
x.rootId = id;
|
}
|
if (!data.children) data.children = [];
|
data.children.push(x);
|
this.getTree(x.id, x, isRootId);
|
}
|
});
|
},
|
getPermission(text) {
|
// return true;
|
return this.datas.find(x => x.text == text);
|
},
|
clickCoupon(url) {
|
// console.log("clickCoupon")
|
if (this.hasLogin()) {
|
this.$u.route(url)
|
} else {
|
this.$t.message.loading('登录失效请重新登录')
|
setTimeout(() => {
|
this.$t.message.closeLoading()
|
this.$u.route({
|
type: 'reLaunch',
|
url: 'pages/login/login'
|
})
|
// this.$Router.replace({name:"tabbar"})
|
}, 1300)
|
}
|
},
|
lock() {
|
console.log("lock")
|
if (this.hasLogin()) {
|
this.$u.route("pages/feeding/feeding")
|
} else {
|
this.$t.message.loading('登录失效请重新登录')
|
setTimeout(() => {
|
|
this.$t.message.closeLoading()
|
this.$u.route({
|
type: 'reLaunch',
|
url: 'pages/login/login'
|
})
|
// this.$Router.replace({name:"tabbar"})
|
}, 1300)
|
}
|
},
|
|
//判断是否登录
|
hasLogin() {
|
let haslogin = uni.getStorageSync('jo_user')
|
if (haslogin == null || haslogin == "") {
|
return false
|
} else {
|
return true
|
}
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
.grid-text {
|
font-size: 30rpx;
|
margin-top: 10rpx;
|
color: $u-type-info;
|
}
|
</style>
|