deviceControl.vue 12 KB

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