quanyawei
2023-11-01 66d2c8d8c97e19fdbd969f97dd3d6a28f27c415f
fix:小程序分享功能和秒级数据
1 files added
7 files modified
467 ■■■■■ changed files
App.vue 12 ●●●●● patch | view | raw | blame | history
manifest.json 8 ●●●●● patch | view | raw | blame | history
pages.json 135 ●●●●● patch | view | raw | blame | history
pages/actionChange/agencyPage/index.vue 2 ●●● patch | view | raw | blame | history
pages/actionChange/secondLevelData/index.vue 189 ●●●● patch | view | raw | blame | history
pages/actionChange/workOrderDetails/index.vue 64 ●●●● patch | view | raw | blame | history
utils/permission.js 55 ●●●●● patch | view | raw | blame | history
utils/share.js 2 ●●● patch | view | raw | blame | history
App.vue
@@ -3,6 +3,7 @@
        getDic
    } from '@/utils/login.js' // 配置文件
    import store from '@/store/index.js'
    import routingIntercept from '@/utils/permission.js'
    import {
        httpPost,
        httpGet
@@ -20,6 +21,7 @@
                        httpGet('/AppUser/wx/login', {
                            'code': loginRes.code
                        }).then(result => {
                            routingIntercept()
                            try {
                                if (result.data.code === 0) {
                                    uni.clearStorageSync()
@@ -55,6 +57,7 @@
                                title: errors,
                                icon: 'none',
                            })
                            this.$isResolve()
                        })
                    }
                })
@@ -149,4 +152,13 @@
            line-height: 30px !important;
        }
    }
    .ridoaBox {
        text-align: center;
        padding: 10px 0px;
        /deep/.u-radio {
            padding-right: 10px;
        }
    }
</style>
manifest.json
@@ -5,7 +5,6 @@
    "versionName": "1.0.0",
    "versionCode": "100",
    "transformPx": false,
    /* 5+App特有相关 */
    "app-plus": {
        "usingComponents": true,
        "nvueStyleCompiler": "uni-app",
@@ -16,11 +15,8 @@
            "autoclose": true,
            "delay": 0
        },
        /* 模块配置 */
        "modules": {},
        /* 应用发布信息 */
        "distribute": {
            /* android打包配置 */
            "android": {
                "permissions": ["<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
                    "<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
@@ -39,15 +35,11 @@
                    "<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
                ]
            },
            /* ios打包配置 */
            "ios": {},
            /* SDK配置 */
            "sdkConfigs": {}
        }
    },
    /* 快应用特有相关 */
    "quickapp": {},
    /* 小程序特有相关 */
    "mp-weixin": {
        "appid": "wxf95fb77e0b1f8c09",
        "__usePrivacyCheck__": true,
pages.json
@@ -1,88 +1,53 @@
{
    "pages": [
        //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
        {
            "path": "pages/index/index",
            "style": {
                "navigationBarTitleText": "首页",
                "enablePullDownRefresh": false,
                "disableSwipeBack": true,
                "navigationStyle": "custom"
            }
        }, {
            "path": "pages/actionChange/agencyPage/index",
            "style": {
                "navigationBarTitleText": "首页",
                "navigationStyle": "custom",
                "enablePullDownRefresh": false
            }
        }, {
            "path": "pages/login/login"
        }, {
            "path": "pages/login/register/register",
            "style": {
                "navigationBarTitleText": "注册",
                "enablePullDownRefresh": false
            }
        }, {
            "path": "pages/actionChange/newPage/index", //立行立改新建交办单
            "style": {
                "navigationBarTitleText": "新建交办单",
                "enablePullDownRefresh": false
            }
        }, {
            "path": "pages/actionChange/workOrderDetails/index", //立行立改交办单详情
            "style": {
                "navigationBarTitleText": "交办单信息",
                "enablePullDownRefresh": false
            }
        }, {
            "path": "pages/actionChange/myInfor/index",
            "style": {
                "navigationBarTitleText": "我的",
                "enablePullDownRefresh": false,
                "disableSwipeBack": true,
                "navigationStyle": "custom"
            }
        }, {
            "path": "pages/actionChange/secondLevelData/index",
            "style": {
                "navigationBarTitleText": "秒级数据",
                "enablePullDownRefresh": false,
                "disableSwipeBack": true
            }
    "pages": [{
        "path": "pages/index/index",
        "style": {
            "navigationBarTitleText": "首页",
            "enablePullDownRefresh": false,
            "disableSwipeBack": true,
            "navigationStyle": "custom"
        }
    ]
    // "tabBar": {
    //     "color": "#515151",
    //     "height": "60px",
    //     "fontSize": "60px",
    //     "selectedFontSize": 20,
    //     "selectedColor": "#3875C5",
    //     "list": [{
    //         "text": "首页",
    //         "pagePath": "pages/actionChange/agencyPage/index",
    //         "iconPath": "static/img/shouye.png",
    //         "selectedIconPath": "static/img/shouyeClick.png",
    //         "textStyle": {
    //             "fontSize": "60px"
    //         }
    //     }, {
    //         "text": "新建交办单",
    //         "pagePath": "pages/actionChange/newPage/index",
    //         "iconPath": "static/img/xinjian.png",
    //         "selectedIconPath": "static/img/xinjianClick.png",
    //         "textStyle": {
    //             "fontSize": "20px"
    //         }
    //     }, {
    //         "text": "我的",
    //         "iconPath": "static/img/wode-.png",
    //         "selectedIconPath": "static/img/wodeClick.png",
    //         "pagePath": "pages/actionChange/myInfor/index",
    //         "textStyle": {
    //             "fontSize": "20px"
    //         }
    //     }]
    // }
    }, {
        "path": "pages/actionChange/agencyPage/index",
        "style": {
            "navigationBarTitleText": "首页",
            "navigationStyle": "custom",
            "enablePullDownRefresh": false
        }
    }, {
        "path": "pages/login/login"
    }, {
        "path": "pages/login/register/register",
        "style": {
            "navigationBarTitleText": "注册",
            "enablePullDownRefresh": false
        }
    }, {
        "path": "pages/actionChange/newPage/index",
        "style": {
            "navigationBarTitleText": "新建交办单",
            "enablePullDownRefresh": false
        }
    }, {
        "path": "pages/actionChange/workOrderDetails/index",
        "style": {
            "navigationBarTitleText": "交办单信息",
            "enablePullDownRefresh": false
        }
    }, {
        "path": "pages/actionChange/myInfor/index",
        "style": {
            "navigationBarTitleText": "我的",
            "enablePullDownRefresh": false,
            "disableSwipeBack": true,
            "navigationStyle": "custom"
        }
    }, {
        "path": "pages/actionChange/secondLevelData/index",
        "style": {
            "navigationBarTitleText": "秒级数据",
            "enablePullDownRefresh": false,
            "disableSwipeBack": true
        }
    }]
}
pages/actionChange/agencyPage/index.vue
@@ -352,7 +352,7 @@
                    data.pageState = e.stateName === '待处理' ? pageState : 'view'
                    let myData = JSON.stringify(data)
                    uni.navigateTo({
                        url: '/pages/actionChange/workOrderDetails/index?infor=' + myData,
                        url: '/pages/actionChange/workOrderDetails/index?infor=' + myData + '&type=jump',
                    })
                })
            },
pages/actionChange/secondLevelData/index.vue
@@ -1,31 +1,44 @@
<template>
    <view class="rootBg">
        <view class="">
            <view class="ridoa">
            <view class="ridoaBox">
                <u-radio-group v-model="value" placement="row" :size='radioOption.size'
                    :labelColor='radioOption.labelColor' :labelSize='radioOption.labelSize' @change='changeSearchType'>
                    <u-radio activeColor="#19be6b" label="通过站点查询" name="0" :labelSize='radioOption.labelSize'
                    <u-radio activeColor="#19be6b" label="Mac号询" name="1" :labelSize='radioOption.labelSize'
                        :labelColor='radioOption.labelColor'></u-radio>
                    <u-radio activeColor="#19be6b" label="通过设查号询" name="1" :labelSize='radioOption.labelSize'
                    <u-radio activeColor="#19be6b" label="站点查询" name="0" :labelSize='radioOption.labelSize'
                        :labelColor='radioOption.labelColor'></u-radio>
                    <u-radio activeColor="#19be6b" label="特殊设备查询" name="2" :labelSize='radioOption.labelSize'
                        :labelColor='radioOption.labelColor'></u-radio>
                </u-radio-group>
            </view>
            <view class="" v-if="value==='1'">
                <u-input placeholder="请输入Mac号" :placeholderStyle='placeholderStyle' color="#fff" v-model='macName'>
                <u-input placeholder="请输入Mac号" :placeholderStyle='placeholderStyle' color="#fff"
                    customStyle="margin: 0 5px;" v-model='macName'>
                    <template slot="suffix">
                        <u-button @tap="searchMacList" text="查询" type="success" size="small"></u-button>
                    </template>
                </u-input>
            </view>
            <view class="" v-else>
            <view class="orgSearch" v-else-if="value==='0'">
                <u-form ref="uForm" label-width="80" :model="form">
                    <u-form-item border-bottom @click="showeEscalationTime = true ;hideKeyboard('orgName','orgId')">
                        <u-input v-model="form.orgName" disabled disabled-color="#ffffff" placeholder="请选择组织"
                            type="select" />
                        <u-input v-model="form.orgName" disabled disabled-color="#ffffff" customStyle="margin: 0 5px;"
                            placeholder="请选择组织" type="select" />
                    </u-form-item>
                    <u-form-item border-bottom @click="selectSite">
                        <u-input v-model="form.siteName" disabled disabled-color="#ffffff" placeholder="请选择站点"
                            type="select" />
                        <u-input v-model="form.siteName" disabled disabled-color="#ffffff" customStyle="margin: 0 5px;"
                            placeholder="请选择站点" type="select" />
                    </u-form-item>
                </u-form>
                <u-picker :show="showeEscalationTime" :columns="columns" @confirm="selectBack" keyName="name"
                    @cancel="showeEscalationTime = false"></u-picker>
            </view>
            <view class="" v-else-if="value==='2'">
                <u-form ref="uForm" label-width="80" :model="form">
                    <u-form-item border-bottom @click="selecSpecial">
                        <u-input v-model="form.specialName" disabled disabled-color="#ffffff"
                            customStyle="margin: 0 5px;" placeholder="请选择设备" type="select" />
                    </u-form-item>
                </u-form>
                <u-picker :show="showeEscalationTime" :columns="columns" @confirm="selectBack" keyName="name"
@@ -55,9 +68,11 @@
        <u-toast ref="uToast"></u-toast>
        <u-modal :show="showModel" title='请选择Mac号' showCancelButton @cancel='showModel=false' @confirm='selectMac'>
            <view class="slot-content">
                <u-radio-group v-model="modeleMacSelect" iconPlacement="right" placement='column' borderBottom='true'>
                <u-radio-group v-model="modeleMacSelect" iconPlacement="right" placement='column' borderBottom='true'
                    @change='clickMac'>
                    <view v-for="(item,index) in macList" :key="index" class="ridioBox">
                        <u-radio activeColor="#19be6b" :label="item.mac" :name="item.mac"></u-radio>
                        <u-radio activeColor="#19be6b" :label="`${item.typeName}: ${item.mac}`"
                            :name="item.mac"></u-radio>
                    </view>
                </u-radio-group>
            </view>
@@ -71,7 +86,7 @@
        data() {
            return {
                modeleMacSelect: '',
                value: '0',
                value: '1',
                showModel: false,
                showeEscalationTime: false,
                columns: [],
@@ -79,7 +94,9 @@
                    orgName: '',
                    orgId: '',
                    siteName: '',
                    siteId: ''
                    siteId: '',
                    specialName: '',
                    specialid: ''
                },
                selectForm: {
                    name: '',
@@ -89,7 +106,7 @@
                radioOption: {
                    size: '20px',
                    labelColor: '#fff',
                    labelSize: '18px'
                    labelSize: '18px',
                },
                placeholderStyle: 'color: #fff',
                macName: '',
@@ -111,7 +128,8 @@
                // 报警圆环图片
                alarmBg: {},
                timer: '',
                isLoading: true
                isLoading: true,
                specialType: '3'
            }
        },
        filters: {
@@ -124,14 +142,13 @@
        computed: {
            windDirData() {
                if (this.wsData2) {
                    console.log('this.windDir', this.windDir)
                    return `${this.windDir} (${this.wsData2.a01008})`
                } else {
                    return ''
                }
            },
            showData() {
                return [...this.defaultMonitorItems, ...this.coreMonitorItems]
                return [...this.coreMonitorItems, ...this.defaultMonitorItems]
            }
        },
        created() {
@@ -144,6 +161,10 @@
            that.timer = ''
        },
        methods: {
            clickMac(e) {
                this.specialType = this.macList.find(item => item.mac === e).specialType
                console.log('specialType', this.specialType)
            },
            getData() {
                this.queryAlarmByMac()
                this.getHourlyAqi()
@@ -151,12 +172,18 @@
            },
            changeSearchType() {
                this.macName = ''
                if (this.value === '2') {
                    this.getSpeciallist()
                }
                if (this.value === '0') {
                    this.getOrgs()
                }
            },
            selectMac() {
                this.macName = this.modeleMacSelect
                this.showModel = false
                if (this.socketTask) {
                    this.socketTask.onClose()
                    this.socketTask.close()
                }
                this.getData()
            },
@@ -164,9 +191,12 @@
                this.$http.httpGet('/AppDevice/fuzzySearch', {
                    mac: this.macName
                }).then(res => {
                    this.showModel = true
                    if (res.data && res.data.length > 10) {
                        this.macList = res.data.slice(0, 10)
                    this.macList = []
                    if (res.data && res.data.length > 0) {
                        this.macList = res.data
                        this.showModel = true
                    } else {
                        uni.$u.toast('暂无数据')
                    }
                }).catch(res => {
                    uni.$u.toast(res)
@@ -186,12 +216,18 @@
                        this.getSites()
                }
            },
            selecSpecial() {
                this.selectForm = {
                    name: 'specialName',
                    id: 'specialId'
                }
                this.showeEscalationTime = true
            },
            hideKeyboard(name, id) {
                this.selectForm = {
                    'name': name,
                    'id': id
                }
                this.getOrgs()
            },
            selectBack(e) {
                if (this.selectForm.name === 'orgName') {
@@ -204,12 +240,13 @@
                } else {
                    this.macName = e.value[0].mac
                    if (this.socketTask) {
                        this.socketTask.onClose()
                        this.socketTask.close()
                    }
                    this.getData()
                }
                this.form[this.selectForm.name] = e.value[0].name
                this.form[this.selectForm.id] = e.value[0].id
                this.specialType = e.value[0].specialType
                this.showeEscalationTime = false
            },
            getOrgs() {
@@ -222,16 +259,14 @@
            },
            getSites() {
                let params = {
                    organizationId: this.form.orgId
                    monitorPointId: this.form.orgId
                }
                this.$http.httpGet('/AppDevice/selectDevice', params).then(res => {
                    console.log(res)
                    this.columns = []
                    this.columns.push(res.data)
                    this.showeEscalationTime = true
                }).catch(res => {
                    uni.$u.toast(res)
                    console.log(res)
                })
            },
            sensorLayout() {
@@ -245,8 +280,21 @@
                    this.fixedMonitorItems = res.data.fixedMonitorItems
                    this.totalArray.push(...this.coreMonitorItems, ...this.defaultMonitorItems, ...this
                        .fixedMonitorItems)
                    this.getSensorMonthAvg()
                    this.connectSocket()
                    if (this.chartSensorKey.length > 0) {
                        this.getSensorMonthAvg()
                        this.connectSocket()
                    } else {
                        uni.$u.toast('暂无数据')
                    }
                }).catch(res => {
                    uni.$u.toast(res)
                })
            },
            // 特殊设备列表
            getSpeciallist() {
                this.$http.httpGet('/AppDevice/specialDevice').then(res => {
                    this.columns = []
                    this.columns.push(res.data)
                }).catch(res => {
                    uni.$u.toast(res)
                    console.log(res)
@@ -418,8 +466,6 @@
                            this.totalArray[i].alarm = this.alarmProgress[key]
                        }
                    }
                    console.log('this.totalArray', this.totalArray)
                    console.log('this.alarmColour', this.alarmColour)
                    for (const key in this.alarmColour) {
                        if (this.totalArray[i].sensorCode === key) {
                            this.totalArray[i].colour = this.alarmColour[key]
@@ -434,15 +480,18 @@
            },
            //连接websocket
            connectSocket() {
                if (!this.isLoading) {
                if (this.socketTask) {
                    this.socketTask.close()
                    this.socketTask = null
                }
                this.baseUrl = this.$storage.get('baseUrl')
                let that = this
                let socketUrl = this.baseUrl + '/singleDevice/' + this.macName
                if (this.specialType === '0') {
                    socketUrl = this.baseUrl + '/cruiserWebsocket/' + this.macName
                }
                socketUrl = socketUrl.replace('https', 'wss').replace('http', 'ws')
                console.log('调用连接websocket')
                console.log('调用连接websocket', socketUrl)
                this.socketTask = uni.connectSocket({
                    url: socketUrl,
                    success(res) {
@@ -463,77 +512,16 @@
                    console.log('收到服务器内容:' + res.data)
                    that.handlerMsg(res) //这里是对获取到的数据进行操作
                })
                this.socketTask.onError(function(res) {
                    console.log('WebSocket连接打开失败,请检查!')
                    console.log(res)
                    // this.isSuccess = false
                    // that.connectSocket()
                    //进入重新连接
                    that.reconnect()
                })
                // // 监听连接关闭 -
                this.socketTask.onClose(e => {
                    console.log('WebSocket连接关闭!')
                    clearInterval(that.timer)
                    that.timer = ''
                    if (!that.isClose) {
                        that.reconnect()
                    }
                })
                console.log(this.socketTask)
            },
            //进入重新连接
            reconnect() {
                console.log('进入断线重连')
                this.socketTask.close()
                this.socketTask = null
                if (this.isLoading) {
                    this.connectSocket()
                }
            },
            //发送消息
            sendSocketMessage(msg) {
                console.log('发送信息')
                console.log(msg)
                return new Promise((reslove, reject) => {
                    this.socketTask.send({
                        data: msg,
                        success(res) {
                            console.log('发送成功')
                            reslove(res)
                        },
                        fail(res) {
                            console.log('发送失败')
                            console.log(res)
                            reject(res)
                        }
                    })
                })
            },
            //心跳
            heart() {
                let that = this
                clearInterval(this.timer)
                this.timer = ''
                let msg = {
                    'type': 'heartbeat',
                }
                this.timer = setInterval(() => {
                    that.sendSocketMessage(JSON.stringify(msg)).then(res => {
                        console.log('心跳成功')
                    }).catch(res => {
                        console.log('发送失败')
                        console.log((res))
                    })
                }, 2000)
            },
            beforeDestroy() {
                if (this.socketTask) {
                    this.socketTask.close()
                    this.socketTask = null
                }
                if (this.timer) {
                    clearInterval(this.timer) // 在Vue实例销毁前,清除我们的定时器
                }
            },
        }
@@ -566,7 +554,7 @@
        justify-content: center;
    }
    .ridoa {
    .ridoaBox {
        text-align: center;
        padding: 10px 0px;
    }
@@ -575,9 +563,11 @@
        color: #fff;
    }
    /deep/.u-form {
        display: flex;
        justify-content: space-evenly;
    .orgSearch {
        /deep/.u-form {
            display: flex;
            justify-content: space-evenly;
        }
    }
    .slot-content {
@@ -593,4 +583,9 @@
    .ridioBox {
        margin-bottom: 10px;
    }
    /deep/.u-modal__content {
        max-height: 300px;
        overflow: auto;
    }
</style>
pages/actionChange/workOrderDetails/index.vue
@@ -14,6 +14,8 @@
                <u-button shape="square" type="primary" @click="submit"> 提交 </u-button>
            </view>
        </view>
        <u-overlay :show="show" :mask-click-able='false' opacity='0.8'>
        </u-overlay>
    </view>
</template>
<script>
@@ -28,27 +30,65 @@
        },
        data() {
            return {
                basicInfor: {}
                basicInfor: {},
                unitListL: [],
                userInfor: null,
                show: false
            }
        },
        computed: {
            pageState() {
                return this.basicInfor.pageState
            }
            },
        },
        created() {
            this.getUnitList()
        },
        onLoad: function(option) {
            console.log('option', option)
            //option为object类型,会序列化上个页面传递的参数
            this.basicInfor = JSON.parse(option.infor)
            this.share.title = '交办单信息'
        },
        onBackPress(e) {
            uni.navigateBack({
                delta: 1, //返回上上一级注意这里要设置为2
            })
            return false
            // let type = JSON.parse(option.type)
            console.log('option', option)
            this.userInfor = JSON.parse(uni.getStorageSync('userInfor') || 'null')
            if (option.type === 'share' && this.userInfor) {
                let params = {
                    allocationNum: this.basicInfor.allocationNum,
                    userId: this.userInfor.userId
                }
                this.$http.httpGet('/allocationApp/authority', params).then(res => {
                    res.data = false
                    if (!res.data) {
                        uni.showModal({
                            content: '您暂无操作权限,请联系管理员!',
                            showCancel: false,
                            confirmText: '确定',
                            success: res => {
                                if (res.confirm) {
                                    uni.reLaunch({
                                        url: '/pages/index/index',
                                    })
                                }
                            },
                        })
                    }
                })
            }
            console.log('this.basicInfor ', this.basicInfor)
        },
        methods: {
            closePop() {},
            getUnitList() {
                this.$http.httpGet('/allocation/unit').then(res => {
                    this.unitList = res.data
                    let data = ''
                    if (this.basicInfor.unitId && this.unitList.length > 0) {
                        data = this.unitList && this.unitList.find(a => Number(a.unitId) === Number(this.basicInfor
                            .unitId)).unitName
                        let time = this.basicInfor.time.slice(5)
                        this.share.title = `${data}-${time}的交办单`
                    }
                })
            },
            radioGroupChange(e) {
                console.log('radioGroupe,e', this.workForme.isChange)
            },
@@ -59,8 +99,8 @@
                        showTabBar: true
                    }
                })
                uni.navigateBack({
                    delta: 1, //返回上上一级注意这里要设置为2
                uni.redirectTo({
                    url: '/pages/index/index',
                })
            },
            refuse() {
utils/permission.js
New file
@@ -0,0 +1,55 @@
// 白名单
const whiteList = [, // 注意入口页必须直接写 '/'
    '/pages/login/login'
]
export default async function() {
    const list = ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab']
    // 添加全局路由拦截
    list.forEach(item => {
        uni.addInterceptor(item, {
            // 路由前拦截
            invoke(args) {
                console.log('navigateTo路由跳转成功', args)
                const token = uni.getStorageSync('tonken')
                const url = args.url.split('?')[0]
                if (token) {
                    if (args.url.includes('/pages/login/login')) {
                        //跳转到首页
                        uni.navigateTo({ url: '/pages/index/index', })
                        return false
                    }
                    return args
                } else {
                    let pass
                    if (whiteList) {
                        pass = whiteList.some(whiteItem => {
                            if (typeof(whiteItem) === 'object' && whiteItem.pattern) {
                                return whiteItem.pattern.test(url)
                            }
                            return url === whiteItem
                        })
                    }
                    console.log('pass', pass)
                    if (!pass) {
                        uni.showModal({
                            title: '未登录',
                            content: '您未登录,需要登录后才能继续',
                            showCancel: false,
                            confirmText: '确定',
                            success: res => {
                                if (res.confirm) {
                                    uni.reLaunch({ url: '/pages/login/login', })
                                }
                            },
                        })
                        return false
                    }
                    return args
                }
            },
            // 路由后拦截
            success(res) {},
            fail(err) {}
        })
    })
}
utils/share.js
@@ -19,7 +19,7 @@
        // console.log("获取加载的页面", pages);
        this.share.path = `/${page.route}`
        if (page.options.infor) {
            this.share.path = `/${page.route}?infor=${page.options.infor}`
            this.share.path = `/${page.route}?infor=${page.options.infor}&type=share`
        }
        console.log('page.options', page.options)
        return {