Bladeren bron

feat(work): 新增房屋管家

wangpx 7 maanden geleden
bovenliggende
commit
901586236d
3 gewijzigde bestanden met toevoegingen van 186 en 22 verwijderingen
  1. 39 0
      api/work.js
  2. 29 10
      pages/work/homesys/index.vue
  3. 118 12
      pages/work/index.vue

+ 39 - 0
api/work.js

@@ -106,4 +106,43 @@ export function getAttendanceSegment(unitId) {
 			}
 		}
 	})
+}
+
+// homeassistant
+// 获取登录flowId
+export function getHomeAssistantLoginFlowId(homeCode) {
+	return request({
+		baseUrl: 'https://api.ygtxfj.com:8125/auth/login_flow',
+		method: 'post',
+		header: {
+			'Content-Type': 'text/plain;charset=UTF-8',
+			'Accept': '*/*',
+			'Pragma': 'no-cache'
+		},
+		data: JSON.stringify({
+			"client_id": "https://api.ygtxfj.com:8125/",
+			"handler": ["homeassistant", null],
+			"redirect_uri": "https://api.ygtxfj.com:8125/"+homeCode+"?kiosk&auth_callback=1"
+		})
+	})
+}
+
+//获取登录校验code
+export function getHomeAssistantLoginCode(flowId, username, password) {
+	return request({
+		baseUrl: `https://api.ygtxfj.com:8125/auth/login_flow/${flowId}`,
+		method: 'post',
+		header: {
+			'Content-Type': 'text/plain;charset=UTF-8',
+			'Accept': '*/*',
+			'Pragma': 'no-cache',
+			'Proxy-Connection': 'keep-alive',
+			'Connection': 'keep-alive'
+		},
+		data: JSON.stringify({
+			"username": username,
+			"password": password,
+			"client_id": "https://api.ygtxfj.com:8125/"
+		})
+	})
 }

+ 29 - 10
pages/work/homesys/index.vue

@@ -12,20 +12,39 @@ import {
 	onMounted,
 	reactive
 } from 'vue';
+import { onLoad } from '@dcloudio/uni-app'
 import { useUserStore } from '@/store/user.js'
+import { getHomeAssistantLoginFlowId, getHomeAssistantLoginCode } from '@/api/work.js'
 const userStore = useUserStore()
 const homeSrc = ref('')
+const homeCode = ref('')
+const authCode = ref('')
+onLoad((options) => {
+	console.log(options)
+	homeCode.value = options.homeCode
+})
 onMounted(() => {
-	switch (userStore.user.userName) {
-		case 'hez':
-			homeSrc.value = 'https://api.ygtxfj.com:8125/lovelace/dongshizhang?kiosk';
-			break;
-		case 'yzadmin':
-			homeSrc.value = 'https://api.ygtxfj.com:8125/lovelace/workshop?kiosk';
-			break;
-		default:
-			break;
-	}
+	const username = 'yunzhuoa'
+	const password = 'HNYZ0821'
+	getHomeAssistantLoginFlowId(homeCode.value).then((data) => {
+		console.log('getHomeAssistantLoginFlowId', data)
+		getHomeAssistantLoginCode(data.flow_id, username, password).then(({result}) => {
+			console.log('getHomeAssistantLoginCode', result);
+			authCode.value = result
+			homeSrc.value = 
+	'https://api.ygtxfj.com:8125/lovelace/'+homeCode.value+'?kiosk=&%3Fauth_callback=1&auth_callback=1&code='+result+'&state=eyJoYXNzVXJsIjoiaHR0cHM6Ly9hcGkueWd0eGZqLmNvbTo4MTI1IiwiY2xpZW50SWQiOiJodHRwczovL2FwaS55Z3R4ZmouY29tOjgxMjUvIn0%3D&storeToken=true'
+		})
+	})
+	// switch (userStore.user.userName) {
+	// 	case 'hez':
+	// 		homeSrc.value = 'https://api.ygtxfj.com:8125/lovelace/dongshizhang?kiosk';
+	// 		break;
+	// 	case 'yzadmin':
+	// 		homeSrc.value = 'https://api.ygtxfj.com:8125/lovelace/workshop?kiosk';
+	// 		break;
+	// 	default:
+	// 		break;
+	// }
 });
 </script>
 

+ 118 - 12
pages/work/index.vue

@@ -67,11 +67,16 @@
 						<text class="text">清除缓存</text>
 					</view>
 				</uni-grid-item>
-				<uni-grid-item :index="3" v-if="homesysShow">
+			</uni-grid>
+		</view>
+		<uni-section title="房屋管家" titleFontSize="1.3rem" v-if="homesysShow" type="line"></uni-section>
+		<view class="grid-body" v-if="homesysShow">
+			<uni-grid :column="uni_grid_column" :showBorder="false" @change="changeHomesys">
+				<uni-grid-item v-for="(code, index) in homesysInfo.homeCode" :index="index" v-if="homesysShow" :key="index">
 					<view class="grid-item-box">
 						<!-- <uni-icons type="home-filled" size="30" color="#66ccff" class="icon_size"></uni-icons> -->
 						<text class="ygoa_work_icon icon-zhinengjiaju"></text>
-						<text class="text">房屋管家</text>
+						<text class="text">{{ roomAliases[code] || code }}</text>
 					</view>
 				</uni-grid-item>
 			</uni-grid>
@@ -110,18 +115,117 @@ if(config.companyCode && config.companyCode == 'yg'){
 	diaryShow.value = false;
 }
 const homesysShow = ref(false)
-onMounted(() => {
-	switch (userStore.user.userName) {
-		case "hez":
-		case "yzadmin":
-			homesysShow.value = true
-			break;
-		default:
-			homesysShow.value = false
+const homesysList = [
+	{
+		name: '测试',
+		username: 'yzadmin',
+		homeCode: [103]
+	},
+	{
+		name: '林明东',
+		username: 'linmd',
+		homeCode: [203, 204, 303, 306, 310]
+	},
+	{
+		name: '何总',
+		username: 'hez',
+		homeCode: [302, 303, 306, 310, 204]
+	},
+	{
+		name: '黄林葳',
+		username: 'huanglw',
+		homeCode: [303, 305, 306, 310, 204]
+	},
+	{
+		name: '余煌',
+		username: 'yuh',
+		homeCode: [202]
+	},
+	{
+		name: '周颖',
+		username: 'zhouy',
+		homeCode: [202]
+	},
+	{
+		name: '谭艳',
+		username: 'tany',
+		homeCode: [101, 204, 208, 303, 306, 310]
+	},
+	{
+		name: '林镇堃',
+		username: 'linzk',
+		homeCode: [106, 107]
+	},
+	{
+		name: '陈雪梅',
+		username: 'chenxm',
+		homeCode: [106, 107]
+	},
+	{
+		name: '陈小沛',
+		username: 'chenxp',
+		homeCode: [301]
+	},
+	{
+		name: '温永志',
+		username: '',
+		homeCode: [102]
+	},
+	{
+		name: '苏总',
+		username: '',
+		homeCode: [209]
+	},
+	{
+		name: '黄铭',
+		username: 'huangm',
+		homeCode: [303, 304, 306, 310]
+	},
+	{
+		name: '黄德胜',
+		username: 'huangds',
+		homeCode: [103]
+	},
+	{
+		name: '黄蓉',
+		username: 'huangr',
+		homeCode: [103]
+	},
+	{
+		name: '潘福雁',
+		username: 'panfy',
+		homeCode: []
+	},
+	{
+		name: '沈宇红',
+		username: 'shenyh',
+		homeCode: [106, 107, 204, 208, 303, 306, 310]
+	},
+	{
+		name: '余总',
+		username: '',
+		homeCode: [207, 204, 208, 303, 306, 310]
 	}
+]
+
+// 房屋别名映射
+const roomAliases = {
+	204: '二楼会议室',
+	208: '休息室',
+	303: '贵宾室',
+	306: '三楼茶室',
+	310: '三楼会议室'
+}
+const homesysInfo = ref({})
+onMounted(() => {
 	sysFontSize = uni.getAppBaseInfo().fontSizeSetting
 	if (sysFontSize > 20) uni_grid_column.value = 3
 	initProcessList()
+	const homesysInfoIndex = homesysList.findIndex(({username}) => userStore.user.userName == username)
+	if (homesysInfoIndex != -1) {
+		homesysShow.value = true
+		homesysInfo.value = homesysList[homesysInfoIndex]
+	}
 })
 
 onShow(()=>{
@@ -188,11 +292,13 @@ function changeToolsGrid(e) {
 			clearCache()
 			// openClearCachePopup() // 打开清除缓存弹出层
 			break
-		case 3:
-			$tab.navigateTo('/pages/work/homesys/index')
 		default:
 	}
 }
+// 点击房屋管家
+function changeHomesys(e) { 
+	$tab.navigateTo('/pages/work/homesys/index?homeCode=' + homesysInfo.value.homeCode[e.detail.index])
+}
 // 计算器
 const calculatorPopup = ref(null)
 function openCalculatorPopup() { // 打开计算器弹出层