deviceControl.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <template>
  2. <view class="device-detail">
  3. <view class="device-detail__header">
  4. <u-icon
  5. size="36"
  6. class="arrow-left"
  7. name="arrow-left"
  8. @click="handleBack"
  9. ></u-icon>
  10. {{ title }}
  11. </view>
  12. <view class="device-detail__body">
  13. <view class="tabs">
  14. <view class="tab-container">
  15. <view class="tab-item" :class="activeTab === 'pestAnalysis'?'active':''" @click="handleTabClick('pestAnalysis')">
  16. 管理员
  17. </view>
  18. <view class="tab-item" :class="activeTab === 'viewImage'?'active':''" @click="handleTabClick('viewImage')">
  19. 设置
  20. </view>
  21. </view>
  22. </view>
  23. <view class="device-detail-content" v-if="activeTab === 'pestAnalysis'">
  24. <view class="device-detail-item">
  25. <text class="device-detail-label">联网模块</text>
  26. <view class="device-detail-btn-container">
  27. <view class="device-detail-btn" @click="setDeviceContorl('dtu_update')">升级</view>
  28. <view class="device-detail-btn" @click="setDeviceContorl('dtu_reboot')">重启</view>
  29. <!-- <view class="device-detail-btn" @click="showMqttConfig">MQTT配置</view> -->
  30. </view>
  31. </view>
  32. <view class="device-detail-item">
  33. <text class="device-detail-label">板子设置</text>
  34. <view class="device-detail-btn-container">
  35. <!-- <view class="device-detail-btn">查看原始IMEI</view> -->
  36. <view class="device-detail-btn" @click="showMqttConfig('imei')">更改IMEI</view>
  37. </view>
  38. </view>
  39. <view class="device-detail-item">
  40. <text class="device-detail-label">强制操作</text>
  41. <view class="device-detail-btn-container">
  42. <view class="device-detail-btn force-btn" @click="setDeviceContorl('takephoto')">拍照</view>
  43. <view class="device-detail-btn force-btn" @click="setDeviceContorl('update')">升级</view>
  44. <view class="device-detail-btn force-btn" @click="setDeviceContorl('reboot')">重启</view>
  45. <view class="device-detail-btn force-btn" @click="setDeviceContorl('open_shake')">震动开启</view>
  46. <view class="device-detail-btn force-btn" @click="setDeviceContorl('close_shake')">震动关闭</view>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="device-detail-content" style="padding-bottom: 50rpx" v-if="activeTab === 'viewImage'">
  51. <view class="device-detail-viewImage">
  52. <text class="device-detail-label">设备开关:</text>
  53. <u-switch v-model="equipContrlForm.ds" size="40" active-color="#0BBC58" active-value="1" inactive-value="0"></u-switch>
  54. </view>
  55. <view class="device-detail-viewImage">
  56. <text class="device-detail-label">定时模式</text>
  57. </view>
  58. <u-radio-group v-model="equipContrlForm.ts" @change="radioGroupChange" active-color="#0BBC58">
  59. <u-radio
  60. :name="0"
  61. >光控
  62. </u-radio>
  63. <u-radio
  64. :name="1"
  65. >时控
  66. </u-radio>
  67. </u-radio-group>
  68. <view class="device-detail-viewImage">
  69. <text class="device-detail-label">落虫时间(min){{ equipContrlForm.collt }}</text>
  70. </view>
  71. <view class="slider-container">
  72. <view class="slider-min-value">0</view>
  73. <u-slider v-model="equipContrlForm.collt" class="slider" max="100" min="0" active-color="#0BBC58"></u-slider>
  74. <view class="slider-max-value">100</view>
  75. </view>
  76. <view class="device-detail-viewImage">
  77. <text class="device-detail-label">加热时间(min){{ equipContrlForm.htim }}</text>
  78. </view>
  79. <view class="slider-container">
  80. <view class="slider-min-value">0</view>
  81. <u-slider v-model="equipContrlForm.htim" class="slider" max="100" min="0" active-color="#0BBC58"></u-slider>
  82. <view class="slider-max-value">100</view>
  83. </view>
  84. <view class="device-detail-viewImage">
  85. <text class="device-detail-label">加热温度(℃){{ equipContrlForm.hst }}</text>
  86. </view>
  87. <view class="slider-container">
  88. <view class="slider-min-value">0</view>
  89. <u-slider v-model="equipContrlForm.hst" class="slider" max="100" min="0" active-color="#0BBC58"></u-slider>
  90. <view class="slider-max-value">100</view>
  91. </view>
  92. <view class="device-detail-viewImage">
  93. <text class="device-detail-label">高温保护阀值(℃){{ equipContrlForm.tph }}</text>
  94. </view>
  95. <view class="slider-container">
  96. <view class="slider-min-value">0</view>
  97. <u-slider v-model="equipContrlForm.tph" class="slider" max="100" min="0" active-color="#0BBC58"></u-slider>
  98. <view class="slider-max-value">100</view>
  99. </view>
  100. <view class="device-detail-viewImage">
  101. <text class="device-detail-label">低温保护阀值(℃){{ equipContrlForm.tpl }}</text>
  102. </view>
  103. <view class="slider-container">
  104. <view class="slider-min-value">0</view>
  105. <u-slider v-model="equipContrlForm.tpl" class="slider" max="100" min="0" active-color="#0BBC58"></u-slider>
  106. <view class="slider-max-value">100</view>
  107. </view>
  108. <view class="device-detail-viewImage">
  109. <text class="device-detail-label">数据上传间隔(min){{ equipContrlForm.datt }}</text>
  110. </view>
  111. <view class="slider-container">
  112. <view class="slider-min-value">0</view>
  113. <u-slider v-model="equipContrlForm.datt" class="slider" max="100" min="0" active-color="#0BBC58"></u-slider>
  114. <view class="slider-max-value">100</view>
  115. </view>
  116. </view>
  117. </view>
  118. <view class="device-detail-btn-footer" v-if="activeTab === 'viewImage'">
  119. <view class="device-detail-btn" @click="saveSettings">保存</view>
  120. </view>
  121. <u-popup v-model="show" mode="bottom">
  122. <view class="device-detail-content" style="height: 50vh">
  123. <view class="device-detail-item">
  124. <text class="device-detail-label">请输入imei</text>
  125. <u-input v-model="equipContrlForm.imei" placeholder="请输入imei"></u-input>
  126. </view>
  127. </view>
  128. <view class="device-detail-btn-footer">
  129. <view class="device-detail-btn" @click="setDeviceContorl('imei')">保存</view>
  130. </view>
  131. </u-popup>
  132. </view>
  133. </template>
  134. <script>
  135. export default {
  136. data(){
  137. return {
  138. value: 10,
  139. imageList: [],
  140. equipContrlForm: {},
  141. time: '',
  142. activeTab: 'pestAnalysis',
  143. title: '设置控制',
  144. deviceType: '',
  145. location: '',
  146. d_id: '',
  147. show: false,
  148. checked: false
  149. }
  150. },
  151. onLoad(options){
  152. this.d_id = options.d_id
  153. this.getControlDeviceConfigInfo()
  154. },
  155. methods: {
  156. handleBack() {
  157. uni.navigateBack({
  158. delta: 1
  159. });
  160. },
  161. handleTabClick(tab) {
  162. this.activeTab = tab;
  163. },
  164. showMqttConfig(){
  165. this.show = true;
  166. },
  167. closeMqttConfig(){
  168. this.show = false;
  169. },
  170. async setDeviceContorl(type){
  171. const data = {
  172. device_type_id: 3,
  173. d_id: this.d_id,
  174. cmd: type,
  175. }
  176. if(type === 'imei'){
  177. data.imei = this.equipContrlForm.imei
  178. }else{
  179. delete data.imei
  180. }
  181. this.$myRequest({
  182. url: '/api/api_gateway?method=forecast.send_control.admin_device_control',
  183. method: 'POST',
  184. data
  185. }).then(res => {
  186. this.closeMqttConfig()
  187. if (res) {
  188. uni.showToast({
  189. title: '设备控制修改成功!',
  190. icon: 'success',
  191. });
  192. } else {
  193. uni.showToast({
  194. title: '设备控制修改失败',
  195. icon: 'error',
  196. });
  197. }
  198. });
  199. },
  200. saveSettings(){
  201. let newForm = Object.assign({}, this.equipContrlForm) // 深拷贝
  202. newForm.st = newForm.st + ''
  203. newForm.et = newForm.et + ''
  204. newForm.st && newForm.st.slice(0, 2).charAt(0) != '0'
  205. ? newForm.st.slice(0, 2)
  206. : newForm.st.slice(1, 2)
  207. newForm.et =
  208. newForm.et && newForm.et.slice(0, 2).charAt(0) != '0'
  209. ? newForm.et.slice(0, 2)
  210. : newForm.et.slice(1, 2)
  211. for (let k in newForm) {
  212. if (typeof newForm[k] === 'number') {
  213. newForm[k] = newForm[k] + ''
  214. }
  215. }
  216. newForm.st = newForm.st.replace(':00', '')
  217. this.$myRequest({
  218. url: '/api/api_gateway?method=forecast.send_control.device_control',
  219. method: 'POST',
  220. data: {
  221. device_type_id: 3,
  222. d_id: this.d_id,
  223. config: JSON.stringify(newForm)
  224. }
  225. }).then(res => {
  226. if (res) {
  227. // 设备控制修改成功
  228. uni.showToast({
  229. title: '设备控制修改成功!',
  230. icon: 'success',
  231. });
  232. } else {
  233. uni.showToast({
  234. title: '设备控制修改失败',
  235. icon: 'error',
  236. });
  237. }
  238. })
  239. },
  240. async getControlDeviceConfigInfo(){
  241. const res = await this.$myRequest({
  242. url: '/api/api_gateway?method=forecast.send_control.device_control_info',
  243. method: 'POST',
  244. data: {
  245. d_id: this.d_id,
  246. cmd:'paramconf'
  247. },
  248. });
  249. this.equipContrlForm = res
  250. },
  251. }
  252. }
  253. </script>
  254. <style scoped lang="scss">
  255. .device-detail {
  256. display: flex;
  257. width: 100%;
  258. height: calc(100vh - 112rpx);
  259. padding-top: 112rpx;
  260. flex-direction: column;
  261. align-items: center;
  262. background: linear-gradient(180deg, #ffffff00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  263. .device-detail__header {
  264. width: 100%;
  265. font-size: 28rpx;
  266. color: #999;
  267. color: #042118;
  268. font-family: 'Source Han Sans CN VF';
  269. font-weight: 700;
  270. position: relative;
  271. text-align: center;
  272. .arrow-left {
  273. position: absolute;
  274. left: 32rpx;
  275. margin-right: 12rpx;
  276. }
  277. }
  278. .device-detail__body {
  279. width: calc(100% - 64rpx);
  280. margin: 0 auto;
  281. border-radius: 16rpx;
  282. overflow-x: hidden;
  283. overflow-y: auto;
  284. // 隐藏滚动条
  285. -ms-overflow-style: none;
  286. scrollbar-width: none;
  287. }
  288. .tabs {
  289. margin: 24rpx 0;
  290. border-radius: 16rpx;
  291. padding: 16rpx 0;
  292. padding-top: 0;
  293. .tab-container{
  294. display: flex;
  295. width: 100%;
  296. height: 88rpx;
  297. line-height: 88rpx;
  298. text-align: center;
  299. font-size: 28rpx;
  300. font-weight: 700;
  301. color: #042118;
  302. font-family: 'Source Han Sans CN VF';
  303. }
  304. .tab-item {
  305. margin-right: 40rpx;
  306. color:#999999;
  307. }
  308. .active{
  309. position: relative;
  310. color: #303133;
  311. text-align: center;
  312. font-family: "Source Han Sans CN VF";
  313. font-size: 28rpx;
  314. font-weight: 700;
  315. &::after {
  316. content: '';
  317. position: absolute;
  318. bottom: 10rpx;
  319. left: 50%;
  320. transform: translateX(-50%);
  321. width: 100%;
  322. height: 36rpx;
  323. border-bottom: 6rpx solid #303133;
  324. }
  325. }
  326. }
  327. .device-detail-content{
  328. display: flex;
  329. padding: 24rpx 32rpx;
  330. flex-direction: column;
  331. align-items: flex-start;
  332. gap: 20rpx;
  333. border-radius: 16rpx;
  334. background: #FFF;
  335. .device-detail-item{
  336. .device-detail-label{
  337. color: #303133;
  338. font-family: "Source Han Sans CN VF";
  339. font-size: 28rpx;
  340. font-weight: 400;
  341. }
  342. .device-detail-btn-container{
  343. display: flex;
  344. gap: 24rpx;
  345. margin-top: 12rpx;
  346. }
  347. .device-detail-btn{
  348. display: flex;
  349. padding: 10rpx 16rpx;
  350. justify-content: center;
  351. align-items: center;
  352. gap: 16rpx;
  353. border-radius: 16rpx;
  354. background: #0BBC58;
  355. color: #ffffff;
  356. font-family: "Source Han Sans CN VF";
  357. font-size: 24rpx;
  358. font-weight: 400;
  359. }
  360. .force-btn{
  361. background: #FB4E52;
  362. }
  363. }
  364. .device-detail-viewImage{
  365. width: 100%;
  366. display: flex;
  367. justify-content: space-between;
  368. align-items: center;
  369. padding-bottom: 20rpx;
  370. }
  371. }
  372. .slider-container{
  373. position: relative;
  374. margin-bottom: 20rpx;
  375. .slider-min-value{
  376. position: absolute;
  377. left: 0;
  378. top: -50rpx;
  379. }
  380. .slider{
  381. width: 600rpx;
  382. }
  383. .slider-max-value{
  384. position: absolute;
  385. right: 0;
  386. top: -50rpx;
  387. }
  388. }
  389. .device-detail-btn-footer{
  390. position: fixed;
  391. bottom: 0;
  392. left: 0;
  393. width: 100%;
  394. height: 112rpx;
  395. line-height: 112rpx;
  396. text-align: center;
  397. font-size: 28rpx;
  398. font-weight: 700;
  399. color: #042118;
  400. font-family: 'Source Han Sans CN VF';
  401. background: #ffffff;
  402. display: flex;
  403. justify-content: center;
  404. align-items: center;
  405. .device-detail-btn{
  406. display: flex;
  407. height: 80rpx;
  408. width: 90%;
  409. margin: 0 auto;
  410. padding: 0rpx 20rpx;
  411. justify-content: center;
  412. align-items: center;
  413. gap: 8rpx;
  414. border-radius: 16rpx;
  415. background:#0BBC58;
  416. color: #ffffff;
  417. text-align: center;
  418. font-family: "Source Han Sans CN VF";
  419. font-size: 14px;
  420. font-style: normal;
  421. font-weight: 500;
  422. }
  423. }
  424. }
  425. </style>