deviceControl.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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" v-if="myuser_type" :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. myuser_type: false,
  145. deviceType: '',
  146. location: '',
  147. d_id: '',
  148. show: false,
  149. checked: false
  150. }
  151. },
  152. onLoad(options){
  153. this.d_id = options.d_id
  154. this.getControlDeviceConfigInfo()
  155. uni.getStorage({
  156. key:"myuser_type",
  157. success:(res)=>{
  158. if(Number(res.data) == 1){
  159. this.myuser_type = true
  160. this.activeTab = 'pestAnalysis'
  161. }else{
  162. this.activeTab = 'viewImage'
  163. }
  164. }
  165. })
  166. },
  167. methods: {
  168. handleBack() {
  169. uni.navigateBack({
  170. delta: 1
  171. });
  172. },
  173. handleTabClick(tab) {
  174. this.activeTab = tab;
  175. },
  176. showMqttConfig(){
  177. this.show = true;
  178. },
  179. closeMqttConfig(){
  180. this.show = false;
  181. },
  182. async setDeviceContorl(type){
  183. const data = {
  184. device_type_id: 3,
  185. d_id: this.d_id,
  186. cmd: type,
  187. }
  188. if(type === 'imei'){
  189. data.imei = this.equipContrlForm.imei
  190. }else{
  191. delete data.imei
  192. }
  193. this.$myRequest({
  194. url: '/api/api_gateway?method=forecast.send_control.admin_device_control',
  195. method: 'POST',
  196. data
  197. }).then(res => {
  198. this.closeMqttConfig()
  199. if (res) {
  200. uni.showToast({
  201. title: '设备控制修改成功!',
  202. icon: 'success',
  203. });
  204. } else {
  205. uni.showToast({
  206. title: '设备控制修改失败',
  207. icon: 'error',
  208. });
  209. }
  210. });
  211. },
  212. saveSettings(){
  213. let newForm = Object.assign({}, this.equipContrlForm) // 深拷贝
  214. newForm.st = newForm.st + ''
  215. newForm.et = newForm.et + ''
  216. newForm.st && newForm.st.slice(0, 2).charAt(0) != '0'
  217. ? newForm.st.slice(0, 2)
  218. : newForm.st.slice(1, 2)
  219. newForm.et =
  220. newForm.et && newForm.et.slice(0, 2).charAt(0) != '0'
  221. ? newForm.et.slice(0, 2)
  222. : newForm.et.slice(1, 2)
  223. for (let k in newForm) {
  224. if (typeof newForm[k] === 'number') {
  225. newForm[k] = newForm[k] + ''
  226. }
  227. }
  228. newForm.st = newForm.st.replace(':00', '')
  229. this.$myRequest({
  230. url: '/api/api_gateway?method=forecast.send_control.device_control',
  231. method: 'POST',
  232. data: {
  233. device_type_id: 3,
  234. d_id: this.d_id,
  235. config: JSON.stringify(newForm)
  236. }
  237. }).then(res => {
  238. if (res) {
  239. // 设备控制修改成功
  240. uni.showToast({
  241. title: '设备控制修改成功!',
  242. icon: 'success',
  243. });
  244. } else {
  245. uni.showToast({
  246. title: '设备控制修改失败',
  247. icon: 'error',
  248. });
  249. }
  250. })
  251. },
  252. async getControlDeviceConfigInfo(){
  253. const res = await this.$myRequest({
  254. url: '/api/api_gateway?method=forecast.send_control.device_control_info',
  255. method: 'POST',
  256. data: {
  257. d_id: this.d_id,
  258. cmd:'paramconf'
  259. },
  260. });
  261. this.equipContrlForm = res
  262. },
  263. }
  264. }
  265. </script>
  266. <style scoped lang="scss">
  267. .device-detail {
  268. display: flex;
  269. width: 100%;
  270. height: calc(100vh - 112rpx);
  271. padding-top: 112rpx;
  272. flex-direction: column;
  273. align-items: center;
  274. background: linear-gradient(180deg, #ffffff00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  275. .device-detail__header {
  276. width: 100%;
  277. font-size: 28rpx;
  278. color: #999;
  279. color: #042118;
  280. font-family: 'Source Han Sans CN VF';
  281. font-weight: 700;
  282. position: relative;
  283. text-align: center;
  284. .arrow-left {
  285. position: absolute;
  286. left: 32rpx;
  287. margin-right: 12rpx;
  288. }
  289. }
  290. .device-detail__body {
  291. width: calc(100% - 64rpx);
  292. margin: 0 auto;
  293. border-radius: 16rpx;
  294. overflow-x: hidden;
  295. overflow-y: auto;
  296. // 隐藏滚动条
  297. -ms-overflow-style: none;
  298. scrollbar-width: none;
  299. }
  300. .tabs {
  301. margin: 24rpx 0;
  302. border-radius: 16rpx;
  303. padding: 16rpx 0;
  304. padding-top: 0;
  305. .tab-container{
  306. display: flex;
  307. width: 100%;
  308. height: 88rpx;
  309. line-height: 88rpx;
  310. text-align: center;
  311. font-size: 28rpx;
  312. font-weight: 700;
  313. color: #042118;
  314. font-family: 'Source Han Sans CN VF';
  315. }
  316. .tab-item {
  317. margin-right: 40rpx;
  318. color:#999999;
  319. }
  320. .active{
  321. position: relative;
  322. color: #303133;
  323. text-align: center;
  324. font-family: "Source Han Sans CN VF";
  325. font-size: 28rpx;
  326. font-weight: 700;
  327. &::after {
  328. content: '';
  329. position: absolute;
  330. bottom: 10rpx;
  331. left: 50%;
  332. transform: translateX(-50%);
  333. width: 100%;
  334. height: 36rpx;
  335. border-bottom: 6rpx solid #303133;
  336. }
  337. }
  338. }
  339. .device-detail-content{
  340. display: flex;
  341. padding: 24rpx 32rpx;
  342. flex-direction: column;
  343. align-items: flex-start;
  344. gap: 20rpx;
  345. border-radius: 16rpx;
  346. background: #FFF;
  347. .device-detail-item{
  348. .device-detail-label{
  349. color: #303133;
  350. font-family: "Source Han Sans CN VF";
  351. font-size: 28rpx;
  352. font-weight: 400;
  353. }
  354. .device-detail-btn-container{
  355. display: flex;
  356. gap: 24rpx;
  357. margin-top: 12rpx;
  358. }
  359. .device-detail-btn{
  360. display: flex;
  361. padding: 10rpx 16rpx;
  362. justify-content: center;
  363. align-items: center;
  364. gap: 16rpx;
  365. border-radius: 16rpx;
  366. background: #0BBC58;
  367. color: #ffffff;
  368. font-family: "Source Han Sans CN VF";
  369. font-size: 24rpx;
  370. font-weight: 400;
  371. }
  372. .force-btn{
  373. background: #FB4E52;
  374. }
  375. }
  376. .device-detail-viewImage{
  377. width: 100%;
  378. display: flex;
  379. justify-content: space-between;
  380. align-items: center;
  381. padding-bottom: 20rpx;
  382. }
  383. }
  384. .slider-container{
  385. position: relative;
  386. margin-bottom: 20rpx;
  387. .slider-min-value{
  388. position: absolute;
  389. left: 0;
  390. top: -50rpx;
  391. }
  392. .slider{
  393. width: 600rpx;
  394. }
  395. .slider-max-value{
  396. position: absolute;
  397. right: 0;
  398. top: -50rpx;
  399. }
  400. }
  401. .device-detail-btn-footer{
  402. position: fixed;
  403. bottom: 0;
  404. left: 0;
  405. width: 100%;
  406. height: 112rpx;
  407. line-height: 112rpx;
  408. text-align: center;
  409. font-size: 28rpx;
  410. font-weight: 700;
  411. color: #042118;
  412. font-family: 'Source Han Sans CN VF';
  413. background: #ffffff;
  414. display: flex;
  415. justify-content: center;
  416. align-items: center;
  417. .device-detail-btn{
  418. display: flex;
  419. height: 80rpx;
  420. width: 90%;
  421. margin: 0 auto;
  422. padding: 0rpx 20rpx;
  423. justify-content: center;
  424. align-items: center;
  425. gap: 8rpx;
  426. border-radius: 16rpx;
  427. background:#0BBC58;
  428. color: #ffffff;
  429. text-align: center;
  430. font-family: "Source Han Sans CN VF";
  431. font-size: 14px;
  432. font-style: normal;
  433. font-weight: 500;
  434. }
  435. }
  436. }
  437. </style>