home.vue 9.88 KB
Newer Older
xinzhedeai's avatar
xinzhedeai committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
<template>
	<view class="wrapper">
		 <CustomNavbar title="" :showLeft="false">
			 <image class="langImg" style="width:55rpx; height: 44rpx;" src="../../static/image/home/change.png" mode="" ></image>
		</CustomNavbar>
		<view class="body-wrapper">
			<view class="logo-wrapper">
				<image class="logoImg" src="/static/image/home/logo.png" alt="" />
				<h3>露天炮孔验收仪</h3>
			</view>
			<p class="list-item">
				<image src="/static/image/home/icon1.png" alt="" />
				<span>登录</span>
				<button size="mini" class="funcBtn" type="primary" @click="navTo('login')">登录</button>
			</p>
			<p class="list-item">
				<image src="/static/image/home/icon1.png" alt="" />
				<span>登录</span>
				<button size="mini" class="funcBtn" type="primary" @click="navTo('import')">导入导出</button>
			</p>
			<p class="list-item">
				<image src="/static/image/home/icon2.png" alt="" />
				<span>连接中深孔验收仪</span>
				<button size="mini" class="funcBtn" type="primary" @click="navTo('link')">连接</button>
			</p>
			<p class="list-item">
				<image src="/static/image/home/icon3.png" alt="" />
				<span>设备测试</span>
				<button size="mini" class="funcBtn" type="primary" @click="navTo('measureTest')">测量</button>
			</p>
			<p class="list-item">  
				<image src="/static/image/home/icon4.png" alt="" />
				<span>炮孔测量</span>
				<button size="mini" class="funcBtn" type="primary" @click="navTo('measure')">测量</button>
			</p>
			<p class="list-item">
				<image src="/static/image/home/icon1.png" alt="" />
				<span>钻孔测量数据列表</span>
				<button size="mini" class="funcBtn" type="primary" @click="navTo('export')">导出</button>
			</p>
			<!-- <p class="list-item">
				<image src="/static/image/home/5.png" alt="" />
				<span>导入数据预览</span>
				<button size="mini" class="funcBtn" type="primary" @click="navTo('importFileDataPreview')">进入</button>
			</p> -->
			<view class="footer">
				<span>
					威海晶合数字矿山技术有限公司
				</span>
			</view>
		</view>
		
	</view>
</template>

<script>
	import CustomNavbar from '@/pages/component/CustomNavbar.vue';
    import {formatNumber,formatDateThis,getUnixTime} from "../../common/dateUtil.js"
	import {showCustomModal, showCustomToast} from "../../common/util.js"
	export default {
		onBackPress(options) {
			// showCustomToast({
			// 	title: '当前页为最后一页,不能继续返回了'
			// })
			// return true
		},
		components: {
		    CustomNavbar,
		  },
		data() {
			return {
				
			}
		},
		onShow() {
			uni.hideLoading()
		}, 
		mounted() {
			uni.hideTabBar()
		},
		methods: {
			exportData2Excel() {
			    //要导出的json数据
			    // const jsonData = [{
			    //         name: '测试数据',
			    //         phone: '123456',
			    //         email: '123@456.com'
			    //     }
			    // ]
				const jsonData =  uni.getStorageSync('importDataList') || []
				if(!jsonData.length){
					showCustomModal({
						content: '本地暂无可导出数据,请确认'
					})
					return
				}
			    //列标题
			    let worksheet = "sheet1";
			    let str = `<tr>
								<td>工程名称</td>
								<td>中段名称</td>
								<td>分段名称</td>
								<td>排位线名称</td>
								<td>炮孔编号</td>
								<td>透孔</td>
								<td>设计孔深</td>
								<td>设计倾角</td>
								<td>实测孔深</td>
								<td>实测倾角</td>
								<td>实测时间</td>
							</tr>`;
			    //循环遍历,每行加入tr标签,每个单元格加td标签
			    for (let i = 0; i < jsonData.length; i++) {
			        str += `<tr>
						<td>${jsonData[i]['engineeringName']}</td>
						<td>${jsonData[i]['middleSectionName']}</td>
						<td>${jsonData[i]['segmentName']}</td>
						<td>${jsonData[i]['alignmentLineName']}</td>
						<td>${jsonData[i]['boreholeNumber']}</td>
						<td>${jsonData[i]['throughHole']}</td>
						<td>${jsonData[i]['designHoleDepth']}</td>
						<td>${jsonData[i]['designInclination']}</td>
						<td>${jsonData[i]['realTestHoleDepth'] || ''}</td>
						<td>${jsonData[i]['realTestInclination'] || ''}</td>
						<td>${jsonData[i]['realTestTime'] || ''}</td>
					</tr>`;
			    }
			    //下载的表格模板数据
			    let template = `<html xmlns:o="urn:schemas-microsoft-com:office:office"
					xmlns:x="urn:schemas-microsoft-com:office:excel"
					xmlns="http://www.w3.org/TR/REC-html40">
					<head><!--[if gte mso 9]><xml encoding="UTF-8"><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>
					<x:Name>${worksheet}</x:Name>
					<x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>
					</x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->
					</head><body><table>${str}</table></body></html>`;
			    //下载模板
			    exportFile(template);
			},
			navTo(flag){
				if(flag === 'export'){
					this.exportData2Excel()
					return
				}
				let url = ''
				if(flag === 'login'){
					// url = 'test'
					url = '/pages/user/login'
				}else if(flag === 'import'){
					url = '/pages/home/importFile'
				}else if(flag === 'measureTest'){
					url = '/pages/home/blueTest'
				}else if(flag === 'measure'){
					url = '/pages/home/blueMeasure'
				}else if(flag === 'link'){
					url = '/pages/home/blueSearch'
				}else if(flag === 'importFileDataPreview'){
					url = '/pages/home/importFileDataPreview'
				}
				uni.navigateTo({
					url
				})
			}
		}
	}
	
	// 导出文件到手机 fileData:要写入到文件的数据,返回参数为文档路径
	function exportFile (fileData,documentName="项目Excel文件") {
	    /*
	    PRIVATE_DOC: 应用私有文档目录常量
	    PUBLIC_DOCUMENTS: 程序公用文档目录常量
	    */
	    plus.io.requestFileSystem(plus.io.PUBLIC_DOCUMENTS, function(fs) {
	 
	        let rootObj = fs.root;
	        let fullPath = rootObj.fullPath;
	        // let reader = rootObj.createReader();
	        // console.log(reader);
	        // reader.readEntries((res)=>{
	        //     console.log(res); //这里拿到了该目录下所有直接文件和目录
	        // },(err)=>{console.log(err);})
	 
	        console.log("开始导出数据********");
	        // 创建文件夹
	        rootObj.getDirectory(documentName, {
	            create: true
	        }, function(dirEntry) {
	            //获取当前的年月继续创建文件夹
	            let date = new Date();
	            let year = date.getFullYear();
	            let month = date.getMonth() + 1;
	            dirEntry.getDirectory(`${year}${month}月`,{
	                create:true
	            },function(dirEntry2){
	                // 创建文件,防止重名
	                let fileName = "excel"+getUnixTime(formatDateThis(new Date()));
	                console.log(fileName);
	                dirEntry2.getFile(`${fileName}.xlsx`, {
	                    create: true
	                }, function(fileEntry) {
	                    fileEntry.createWriter(function(writer) {
	                        writer.onwritestart = (e)=>{
	                            uni.showLoading({
	                                title:"正在导出",
	                                mask:true
	                            })
	                        }
	 
	                        //  /storage/emulated/0指的就是系统路径
	                        let pathStr = fullPath.replace("/storage/emulated/0","");
	                        writer.onwrite = (e) => {
	                            // 成功导出数据;
	                            uni.hideLoading();
	                            setTimeout(()=>{
									showCustomModal({
										content: `导出成功=>文件位置:${pathStr}/${documentName}/${year}${month}月`
									})
	                                // uni.showToast({
	                                //     title:"成功导出",
	                                //     icon:"success"
	                                // })
	                                // that.successTip = `文件位置:${pathStr}/${documentName}/${year}年${month}月`;
									
	                            },500)
	 
	                        };
	                        // 写入内容;
	                        writer.write(fileData);
	 
	                    }, function(e) {
	                        console.log(e.message);
	                    });
	                });
	            })
	 
	        });
	 
	    });
	 
	}
	
	
</script>
<style lang="scss">
.wrapper{
	width: 100vw;
	height: calc(100vh-44rpx);
	padding-top: 44rpx;
	background: linear-gradient(180deg, #007AFF 0%, #419AFF 16%, #EFF1F4 43%);
	position: relative;
	.footer{
		// position: absolute;
		// bottom: 10rpx;
		width: 100%;
		// padding-top: 200rpx;
		// height: 10rpx;
		// height: 120rpx;
		// line-height: 120rpx;
		text-align: center;
		span{
			font-weight: 400;
			font-size: 27rpx;
			color: #A0A7AE;
		}
	}
}
.body-wrapper{
	display: flex;
	justify-content: center;
	flex-direction: column;
	align-items: center;
	gap: 20rpx;
	background-color: linear-gradient(180deg, #007AFF 0%, #419AFF 16%, #EFF1F4 43%);;
}
.logo-wrapper{
	position: relative;
	height: 300rpx;
	display: flex;
	justify-content: center;
	flex-direction: column;
	align-items: center;
	gap: 50rpx;
	font-family: Source Han Sans SC;
	.logoImg{
		width: 454rpx;
		height: 98rpx;
	}
	h3{
		color: #ffffff;
		font-size: 37rpx;
	}
}
.list-item{
	width: 660rpx;
	height: 140rpx;
	// border-top: 1px solid rgba(187,187,187,1);
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 0px 30px;
	padding: 10px;
	background-color: #ffffff;
	border-radius: 10rpx;
	image{
		width: 102rpx;
		height: 102rpx;
	}
	span{
		display: inline-block;
		width: 320rpx;
		font-family: PingFangSC-regular;
		color: rgba(0,0,0,1);
		font-size: 18px;
		font-weight: bold;
	}
	.funcBtn{
		width: 120rpx;
		height: 62rpx;
		line-height: 62rpx;
		background: #FFFFFF;
		border-radius: 36rpx;
		border: 2rpx solid #007AFF;
		color: #007AFF;
		padding: 0;
		// font-size: 27rp;
		font-family: Source Han Sans SC;
		font-weight: bold;
		
	}
}
</style>