uniapp开发鸿蒙常见问题

如何在应用中加入版权信息,并显示

    <view class="copyright">
        <text class="copyright-text">© 2024 坚果派</text>
        <text class="copyright-text">公众号:nutpi</text>
        <text class="copyright-text">电话:17752170152</text>
        <text class="copyright-text">官网:https://www.nutpi.net/</text>
    </view>

image-20250308080949413

如何加入设备类型等

<template>
    <view class="content">
        <!-- ... 现有搜索框和结果显示代码 ... -->
        
        <view class="system-info" v-if="systemInfo">
            <view class="info-title">设备信息</view>
            <view class="info-item">
                <text class="info-label">设备品牌:</text>
                <text class="info-value">{{ systemInfo.brand }}</text>
            </view>
            <view class="info-item">
                <text class="info-label">设备型号:</text>
                <text class="info-value">{{ systemInfo.model }}</text>
            </view>
            <view class="info-item">
                <text class="info-label">系统类型:</text>
                <text class="info-value">{{ systemInfo.platform }}</text>
            </view>
            <view class="info-item">
                <text class="info-label">系统版本:</text>
                <text class="info-value">{{ systemInfo.system }}</text>
            </view>
        </view>

        <view class="copyright">
            <!-- ... 现有版权信息代码 ... -->
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            searchName: '',
            result: null,
            systemInfo: null
        }
    },
    onLoad() {
        this.getSystemInfo()
    },
    methods: {
        // ... 现有的其他方法 ...
        
        getSystemInfo() {
            try {
                this.systemInfo = uni.getSystemInfoSync()
            } catch (e) {
                console.error('获取系统信息失败:', e)
            }
        }
    }
}
</script>

<style>
/* ... 现有样式代码 ... */

.system-info {
    margin-top: 30rpx;
    padding: 20rpx;
    background-color: #f8f8f8;
    border-radius: 8rpx;
}

.info-title {
    font-size: 28rpx;
    color: #333;
    font-weight: bold;
    margin-bottom: 20rpx;
}

.info-item {
    display: flex;
    margin-bottom: 10rpx;
}

.info-label {
    color: #666;
    font-size: 26rpx;
    width: 160rpx;
}

.info-value {
    color: #333;
    font-size: 26rpx;
    flex: 1;
}
</style>

image-20250308081423247

加入网络连接的类型,是卡,还是wifi,是4g还是5g

        <view class="system-info" v-if="systemInfo">
            <view class="info-title">设备信息</view>
            <view class="info-item">
                <text class="info-label">设备品牌:</text>
                <text class="info-value">{{ systemInfo.brand }}</text>
            </view>
            <view class="info-item">
                <text class="info-label">设备型号:</text>
                <text class="info-value">{{ systemInfo.model }}</text>
            </view>
            <view class="info-item">
                <text class="info-label">系统类型:</text>
                <text class="info-value">{{ systemInfo.platform }}</text>
            </view>
            <view class="info-item">
                <text class="info-label">系统版本:</text>
                <text class="info-value">{{ systemInfo.system }}</text>
            </view>
            <view class="info-item">
                <text class="info-label">网络类型:</text>
                <text class="info-value">{{ networkType }}</text>
            </view>
        </view>
    data() {
        return {
            searchName: '',
            result: null,
            systemInfo: null,
            networkType: '未知'
        }
    },
    onLoad() {
        this.getSystemInfo()
        this.getNetworkType()
    },
    methods: {
        // ... 现有方法 ...
        
        getSystemInfo() {
            try {
                this.systemInfo = uni.getSystemInfoSync()
            } catch (e) {
                console.error('获取系统信息失败:', e)
            }
        },
        
        getNetworkType() {
            uni.getNetworkType({
                success: (res) => {
                    this.networkType = res.networkType
                    // 监听网络状态变化
                    uni.onNetworkStatusChange((res) => {
                        this.networkType = res.networkType
                    })
                },
                fail: () => {
                    this.networkType = '获取失败'
                }
            })
        }
    }

image-20250308081750748

如何进行条件编译

仅 APP-HARMONY 和 APP 可以条件编译命中鸿蒙平台,APP-PLUS 不能命中中鸿蒙平台

// #ifdef APP-HARMONY
console.log("仅鸿蒙会编译")
// #endif

// #ifndef APP-HARMONY
console.log("仅非鸿蒙会编译")
// #endif

// #ifdef APP
console.log("安卓、苹果、鸿蒙会编译,小程序和Web不会编译")
// #endif

// #ifndef APP
console.log("安卓、苹果、鸿蒙不会编译,小程序和Web会编译")
// #endif

// #ifdef APP-PLUS
console.log("安卓、苹果会编译,鸿蒙不会编译,小程序和Web也不会编译")
// #endif

// #ifndef APP-PLUS
console.log("安卓、苹果不会编译,鸿蒙会编译,小程序和Web也会编译")
// #endif

完毕


坚果
80 声望9 粉丝