| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- <template>
- <!-- 顶部弹出 -->
- <van-popup v-model:show="showSearch" position="top" :close-on-click-overlay="true">
- <div style="padding: 16px;">
- <div style="background-color: #eee; border-radius: 2.5rem; margin: 0px 5px;">
- <van-field style="padding: 6px 16px;" v-model="keyWord" size="normal" clearable />
- </div>
- <div style="margin-top: 16px; display: flex;">
- <div style="flex-grow: 1;">
- <van-button type="primary" size="normal" round block @click="onSearch">搜索</van-button>
- </div>
- <div style="width: 10px;"></div>
- <div style="flex-grow: 1;">
- <van-button type="warning" size="normal" round block @click="() => {showSearch = false}">取消</van-button>
- </div>
- </div>
- </div>
- </van-popup>
- <!-- 顶部弹出 -->
- <van-popup v-model:show="showMore" position="top">
- <div style="padding: 16px;">
- <div>
- <van-button type="primary" size="normal" icon="scan" round block @click="onScan">扫码添加设备</van-button>
- </div>
- </div>
- </van-popup>
- <!-- 相机界面 -->
- <!-- <van-popup v-model:show="showScan" position="top">
- <div style="width: 100vw; height: 100vh; background-color: #ccc;">
- <QRScreen ref="scanQR" @success="scanSuccess"></QRScreen>
- </div>
- </van-popup> -->
- <!-- 扫描二维码的界面-相机界面 -->
- <div v-show="showScan" style="position: absolute;
- width: 100vw; height: 100vh; top: 0; left: 0;
- z-index: 99; background-color: #ccc;">
- <QRScreen ref="scanQR" @success="scanSuccess"></QRScreen>
- </div>
- <!-- 页面内容 -->
- <div style="display: flex; flex-direction:column;height: 100vh;">
-
- <!-- 店铺名称 -->
- <div style="padding: 10px 16px 10px 16px;">
- <div style="display: flex;
- justify-content:space-between;
- align-items:center;">
- <div style="display: flex; align-items: flex-end;">
- <div style="font-size: 20px; font-weight: bold;">
- <span>设备</span>
- </div>
- <div style="font-size: 0.9rem; margin-left: 5px;">
- <span>共{{ page.total }}台</span>
- </div>
- </div>
- <div style="background-color: #eee; border-radius: 2.5rem; width: 0px; flex-grow: 1; margin: 0px 5px;">
-
- </div>
- <div style="line-height: 0px;" @click="()=>{showSearch = true}">
- <van-icon name="static/images/icon-search-black.png" size="2rem" />
- </div>
- <div style="line-height: 0px;" @click="()=>{showMore = true}">
- <van-icon name="plus" size="1.5rem" />
- </div>
- </div>
- </div>
-
- <div ref="scrollRef" class="container" style="overflow-y: auto; flex-grow: 1;">
- <van-pull-refresh style="min-height: 100%;" v-model="refreshing" @refresh="onRefresh">
- <van-swipe-cell v-for="item in dataList" style="background-color: #fff; margin-bottom: 10px;">
- <template #right>
- <div style="width: 50px; height: 100%; background-color: red;
- display: flex; justify-content:center; align-items: center;">
- <div>
- <div style="color: #fff; font-weight: bold;">
- <span>删除</span>
- </div>
- </div>
- </div>
- </template>
- <van-cell clickable :to="'/device/detail/'+item.mac">
- <div style="text-align: left;">
- <!-- 第一行 -->
- <div style="display: flex; justify-content: space-between; margin-bottom: 5px;">
- <div style=" font-size: 0.9rem;">
- <span v-if="item.username" style="color: #000;">{{item.username}}</span>
- <span v-else>未知用户</span>
- </div>
- <div style="font-size: 0.9rem;">{{ item.productName }}</div>
- </div>
- <!-- 第二行 -->
- <div style="display: flex; align-items: flex-end;">
- <div style="color: #000; font-weight: bold; font-size: 1.1rem;">
- <span>{{ item.mac }}</span>
- </div>
- <div style="margin-left: 5px; margin-bottom: 2px;">
- <template v-if="getTimeSpan(item.modifytime) < 1200">
- <van-tag round size="medium" type="success">在线</van-tag>
- </template>
- <template v-else>
- <van-tag round size="medium" type="danger">离线</van-tag>
- </template>
- </div>
- </div>
- <!-- 第三行 -->
- <div style="display: flex; justify-content: space-between; margin-bottom: 5px;">
- <div style="font-size: 0.9rem; margin-left: 0px;">
- <span>{{ item.createtime }}</span>
- </div>
- <div style="font-size: 0.9rem; margin-left: 0px;">
- <span>{{item.modifytime}}</span>
- </div>
- </div>
- <!-- 第四行 -->
- <div style="display: flex; justify-content: space-between;">
- <div v-if="JSON.parse(item.data).lat" style="display: flex; color: #000;" @click.stop="onLocation(item.mac)">
- <div>
- <van-icon name="static/images/icon-location2.png" size="1.5rem" />
- </div>
- <div style="margin-left: 3px;">位置</div>
- </div>
- <div v-else>暂无定位</div>
- <div></div>
- <div style="display: flex; color: #000;" @click.stop="onLog(item.mac)">
- <div>
- <van-icon name="static/images/icon-log.png" size="1.5rem" />
- </div>
- <div style="margin-left: 3px;">传输日志</div>
- </div>
- <!-- <div style="display: flex; color: #000;">
- <div>
- <van-icon name="static/images/icon-edit.png" size="1.5rem" />
- </div>
- <div style="margin-left: 3px;">编辑</div>
- </div> -->
- </div>
-
- </div>
- </van-cell>
- </van-swipe-cell>
- <!-- 数据提示 -->
- <div>
- <div v-if="refreshing"></div>
- <div v-else-if="dataList.length == 0" style="text-align: center; padding: 20px; color: #ccc;">
- <span>暂无数据</span>
- </div>
- <div v-else-if="isLoading" style="text-align: center; padding: 20px;">
- <van-loading type="spinner" color="#1989fa" />
- </div>
- <div v-else-if="page.pages <= page.pageNum" style="text-align: center; padding: 20px; color: #ccc;">
- <span>没有更多了</span>
- </div>
- <div v-else style="text-align: center; padding: 20px;">
- <span @click="clickLoading">点击加载</span>
- </div>
- </div>
- <div style="height: 60px; "></div>
- </van-pull-refresh>
- <!-- 返回顶部 -->
- <van-back-top target=".container" right="5vw" bottom="80px" />
- </div>
- </div>
-
- </template>
- <script setup lang="ts">
- import { onMounted, reactive, ref, onActivated, nextTick } from 'vue';
- import { onBeforeRouteLeave, useRouter } from 'vue-router'
- import { post_promise } from '@/network/axios';
- import QRScreen from '@/components/QR/Index.vue';
- import { showToast } from 'vant';
- // import { showToast } from 'vant'
- // 弹出
- const showSearch = ref(false);
- const showMore = ref(false);
- const showScan = ref(false);
- const onSearch = () => {
- onRefresh();
- showSearch.value = false
- }
- const onScan = () => {
- showMore.value = false;
- showScan.value = true;
- scanQR.value.open();
- }
- // 扫码结果
- const scanQR = ref();
- const scanSuccess = (e: any) => {
- showScan.value = false
- console.log(e)
- showToast(e.decodedText);
- }
- // 路由
- const router = useRouter();
- const onLocation = (deviceId: string) => {
- console.log(deviceId)
- // 跳转到定位
- router.push('/device/location/' + deviceId)
- }
- // 跳转到日志
- const onLog = (deviceId: string) => {
- console.log(deviceId)
- // 跳转到定位
- router.push('/device/log/' + deviceId)
- }
- // 搜索关键字
- const keyWord = ref('');
- // 分页
- const page = reactive({
- total: 0,
- pageNum: 1,
- pageSize: 10,
- pages: 0,
- })
- const dataList = ref<any[]>([]);
- const refreshing = ref(false);
- const isLoading = ref(false);
- const finished = ref(false);
- // 获取数据
- const getData = () => {
- console.log('onload.....')
- post_promise({url: '/device/search', data: {
- size: page.pageSize,
- page: page.pageNum,
- sort: "createtime",
- order: "desc",
- keyWord: keyWord.value,
- mac: ''
- }})
- .then((result) => {
- console.log(result)
- // 刷新结束
- isLoading.value = false;
- refreshing.value = false;
- // 处理成功结果
- if(result.code == 0){
- // 下拉刷新时清空列表
- const dataArr:any[] = result.data;
- const total = result.total;
- const pages = Math.ceil(total / page.pageSize);
- console.log(pages);
- console.log(dataArr)
-
- if(page.pageNum == 1){
- dataList.value.splice(0, dataList.value.length);
- }
- dataList.value.push(...dataArr);
- page.pages = pages
- page.total = total
- console.log(dataList.value, pages)
- }
- },(result) => {
- console.log(result)
- isLoading.value = false;
- refreshing.value = false;
- // 跳转到首页
- }).catch((ex) => {
- console.log(ex)
- isLoading.value = false;
- refreshing.value = false;
- // 跳转到首页
- })
- };
- const onRefresh = () => {
- console.log('onrefresh...')
- console.log(refreshing.value)
- page.pageNum = 1;
- // 清空列表数据
- finished.value = false;
- // 重新加载数据
- // 将 loading 设置为 true,表示处于加载状态
- isLoading.value = true;
- getData();
- };
- const getTimeSpan = (time: string) => {
- const before = Date.parse(time);
- const now = new Date().getTime();
- return (now - before) / 1000;
- }
- // 生命周期
- onMounted(() => {
- console.log('onMounted');
- // const before = Date.parse("2011-10-10 14:48:00");
- // const now = Date.parse("2011-10-10 15:08:00");
- // console.log(before)
- // console.log(now)
- // console.log(now - before)
- getData();
- })
- // 页面切换时缓存滚动条
- const scrollRef = ref<any>(null)
- const scrollTop = ref(0)
- onActivated(() => {
- console.log('onActived...')
- nextTick(() => {
- scrollRef.value.scrollTop = scrollTop.value
- })
- })
- onBeforeRouteLeave((to, from, next) => {
- console.log(to, from);
- console.log('onBeforeRouteLeave...')
- scrollTop.value = scrollRef.value.scrollTop
- next();
- })
- // 点击加载
- const clickLoading = () => {
- console.log('clickLoading');
- page.pageNum++
- isLoading.value = true
- getData();
- }
- </script>
- <style scoped>
- </style>
|