my.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="所属医生" prop="doctorId">
  5. <el-input v-model="queryParams.doctorName" placeholder="请输入所属医生" clearable size="small"
  6. @keyup.enter.native="handleQuery" />
  7. </el-form-item>
  8. <!-- <el-form-item label="绑定用户" prop="watchUserName">
  9. <el-input v-model="queryParams.watchUserName" placeholder="请输入绑定用户" clearable size="small"
  10. @keyup.enter.native="handleQuery" />
  11. </el-form-item> -->
  12. <el-form-item label="设备编号" prop="deviceNumber">
  13. <el-input v-model="queryParams.deviceNumber" placeholder="请输入设备编号" clearable size="small"
  14. @keyup.enter.native="handleQuery" />
  15. </el-form-item>
  16. <el-form-item label="绑定状态" prop="lifeStatus">
  17. <el-select v-model="queryParams.lifeStatus" placeholder="请选择绑定状态" clearable size="small">
  18. <!-- <el-option label="请选择字典生成" value="" /> -->
  19. <el-option v-for="item in lifeStatusOptions" :key="item.value" :label="item.label" :value="item.value">
  20. </el-option>
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="设备状态" prop="status">
  24. <el-select v-model="queryParams.status" placeholder="请选择设备状态" clearable size="small">
  25. <!-- <el-option label="请选择字典生成" value="" /> -->
  26. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
  27. </el-option>
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item>
  31. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  32. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  33. </el-form-item>
  34. </el-form>
  35. <el-row :gutter="10" class="mb8">
  36. <el-col :span="1.5">
  37. <el-button type="warning" plain icon="el-icon-download" size="mini" :loading="exportLoading"
  38. @click="handleExport" v-hasPermi="['watchApi:deviceInfo:export']">导出</el-button>
  39. </el-col>
  40. <el-col :span="1.5">
  41. <el-popover placement="right" width="400" trigger="click" @show="refreshPageAlarm">
  42. <div>
  43. <div class="clearfix" style="padding: 10px; border-bottom: 1px solid #ebeef5;">
  44. <span>预警通知</span>
  45. <el-button style="float: right; padding: 3px 0" type="text" @click="markAllAsRead"
  46. v-if="alarmData && alarmData.length > 0">一键已读</el-button>
  47. </div>
  48. <div class="notification-container" v-infinite-scroll="load">
  49. <el-card v-for="(notification, index) in alarmData" :key="index" class="notification-card">
  50. <!-- 红点标记 -->
  51. <div v-if="notification.status === 0" class="red-dot"></div>
  52. <el-row @click="goDetailPage(notification)">
  53. <el-col :span="20" :style="{ opacity: notification.status == 1 ? 0.6 : 1 }">
  54. <div class="notification-title">{{ notification.title }}</div>
  55. <div class="notification-desc">{{ notification.description }}</div>
  56. <div class="notification-time">{{ notification.dateTime }}</div>
  57. </el-col>
  58. <el-col :span="4" class="notification-status">
  59. <el-button style="float: right; padding: 3px 0" type="text" size="mini"
  60. @click="readItem(notification)">阅读</el-button>
  61. </el-col>
  62. </el-row>
  63. </el-card>
  64. </div>
  65. </div>
  66. <!-- 触发弹出框的按钮 -->
  67. <el-button type="info" plain icon="el-icon-bell" size="mini" slot="reference">预警通知</el-button>
  68. </el-popover>
  69. </el-col>
  70. <el-col :span="1.5">
  71. <el-button plain icon="el-icon-setting" size="mini" @click="sendMsg" :disabled="sendMsgButtonDisabled"
  72. v-hasPermi="['watchApi:deviceInfo:edit']">看课提醒</el-button>
  73. </el-col>
  74. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  75. </el-row>
  76. <el-table v-loading="loading" :data="deviceInfoList" @selection-change="handleSelectionChange">
  77. <el-table-column type="selection" width="55" align="center" />
  78. <el-table-column label="设备id" align="center" prop="deviceId" />
  79. <el-table-column label="所属医生" align="center" prop="doctorName" />
  80. <el-table-column label="绑定用户" align="center">
  81. <template slot-scope="scope">
  82. <el-link :underline="false" prop="item.userId" v-for="(item, index) in scope.row.users" v-if="scope.row.users" @click="handleDetails(scope.row.deviceId,item.userId,0)">{{item.nickName}}</el-link>
  83. </template>
  84. </el-table-column>
  85. <el-table-column label="绑定家人用户" align="center">
  86. <template slot-scope="scope">
  87. <el-link :underline="false" prop="item.userId" v-for="(item, index) in scope.row.familyUsers" v-if="scope.row.familyUsers" @click="handleDetails(scope.row.deviceId,item.userId,1)">{{item.nickName}}</el-link>
  88. </template>
  89. </el-table-column>
  90. <el-table-column label="设备编号" align="center" prop="deviceNumber" width="150"/>
  91. <el-table-column label="电量" align="center" prop="battery" />
  92. <el-table-column label="信号" align="center" prop="rssi" />
  93. <el-table-column label="绑定状态" align="center" prop="lifeStatusOut" />
  94. <el-table-column label="设备状态" align="center" prop="statusOut" />
  95. <el-table-column label="最新健康数据" align="center" width="120" >
  96. <template slot-scope="scope">
  97. <span
  98. @click="showHealthData(scope.row.deviceNumber)"
  99. style="cursor: pointer; color: #409EFF;"
  100. >
  101. 最新数据
  102. </span>
  103. <el-tag size="mini" :type="scope.row.isNormal == '异常'?'danger':'primary'">{{scope.row.isNormal}}</el-tag>
  104. </template>
  105. </el-table-column>
  106. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  107. <template slot-scope="scope">
  108. <el-button size="mini" type="text" icon="el-icon-view" @click="handleDetails(scope.row.deviceId,null,0)"
  109. v-hasPermi="['watchApi:deviceInfo:query']">查询详情</el-button>
  110. <el-button size="mini" type="text" icon="el-icon-phone-outline" @click="handleSoSPeople(scope.row.deviceNumber)"
  111. v-hasPermi="['watchApi:deviceInfo:query']">查看紧急联系人</el-button>
  112. </template>
  113. </el-table-column>
  114. </el-table>
  115. <!-- 弹窗展示紧急联系人列表 -->
  116. <el-dialog :visible.sync="sosVisible" title="紧急联系人" width="50%">
  117. <el-table v-loading="sosLoading" :data="sosPeopleList">
  118. <el-table-column prop="name" label="联系人" align="center" />
  119. <el-table-column prop="number" label="电话" align="center" />
  120. </el-table>
  121. <div slot="footer" class="dialog-footer">
  122. <el-button @click="sosVisible = false">关闭</el-button>
  123. </div>
  124. </el-dialog>
  125. <!-- 弹窗展示最新健康数据列表 -->
  126. <el-dialog :visible.sync="healthDataDialogVisible" title="最新健康数据" width="50%">
  127. <el-table :data="selectedHealthData" :row-class-name="rowClassName">
  128. <el-table-column prop="type" label="类型" align="center" />
  129. <el-table-column prop="data" label="数值" align="center" />
  130. <el-table-column prop="status" label="状态" align="center" />
  131. <el-table-column prop="date" label="时间" align="center" />
  132. </el-table>
  133. <div slot="footer" class="dialog-footer">
  134. <el-button @click="healthDataDialogVisible = false">关闭</el-button>
  135. </div>
  136. </el-dialog>
  137. <!-- 消息发送弹窗 -->
  138. <el-dialog :visible.sync="showSend" :title="senFormTitle" width="40%">
  139. <el-form :model="sendForm" :rules="sendRules" label-width="100px" ref="sendForm">
  140. <el-form-item label="标题" prop="title">
  141. <el-input v-model="sendForm.title"></el-input>
  142. </el-form-item>
  143. <el-form-item label="详情" prop="description">
  144. <el-input type="textarea" v-model="sendForm.description"></el-input>
  145. </el-form-item>
  146. </el-form>
  147. <div slot="footer" class="dialog-footer">
  148. <el-button type="primary" @click="submitSendForm">确 定</el-button>
  149. <el-button @click="cancel">取 消</el-button>
  150. </div>
  151. </el-dialog>
  152. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
  153. @pagination="getList" />
  154. <setUpUserInfoDialog ref="setUpUserInfoDialog" />
  155. <!-- 其他设置弹窗 -->
  156. <SetInfoDialog ref="setInfoDialog" @refreshList="getList" />
  157. <!-- 下发通讯录弹窗 -->
  158. <Phonebook ref="phonebook" />
  159. <!-- 设置闹钟 -->
  160. <Clockalarm ref="clockalarm" />
  161. <!-- 设置久坐 -->
  162. <Sedentary ref="sedentary" />
  163. </div>
  164. </template>
  165. <script>
  166. import { myDeviceInfo, getDeviceInfo, delDeviceInfo, addDeviceInfo, updateDeviceInfo, exportMy, queryAlarm, setStatus, queryPageAlarm,queryLastHealthData,querySos} from "@/api/watch/deviceInfo";
  167. import { getAllUserlist } from "@/api/company/companyUser";
  168. import { messageSend } from "@/api/watch/deviceInfoSet.js";
  169. import setUpUserInfoDialog from "@/components/DeviceInfo/SettingDialog/setUpUserInfoDialog.vue";
  170. import SetInfoDialog from "@/components/DeviceInfo/SettingDialog/SetInfoDialog.vue";
  171. import Phonebook from "@/components/DeviceInfo/SettingDialog/Phonebook.vue";
  172. import Clockalarm from "@/components/DeviceInfo/SettingDialog/Clockalarm.vue";
  173. import Sedentary from "@/components/DeviceInfo/SettingDialog/Sedentary.vue";
  174. // import {getInfo} from "@/api/login"
  175. export default {
  176. name: "my",
  177. components: {
  178. setUpUserInfoDialog,
  179. SetInfoDialog,
  180. Phonebook,
  181. Clockalarm,
  182. Sedentary
  183. },
  184. data() {
  185. return {
  186. sosVisible: false,
  187. sosLoading: false,
  188. sosPeopleList: [],
  189. // healthDataloading: false,
  190. deviceInfoList: [], // 设备信息列表
  191. healthDataDialogVisible: false, // 控制弹窗显示
  192. selectedHealthData: [], // 选中设备的健康数据列表
  193. roles: null, // 登录用户信息
  194. // 查询参数
  195. queryAlarmParams: {
  196. pageNum: 1,
  197. pageSize: 10
  198. },
  199. alarmTotal: 0,
  200. alarmData: [],
  201. hasMore: true,
  202. // 遮罩层
  203. loading: true,
  204. // 导出遮罩层
  205. exportLoading: false,
  206. // 选中数组
  207. ids: [],
  208. // 选中编号数组
  209. deviceNumbers: [],
  210. // 非单个禁用
  211. single: true,
  212. // 非多个禁用
  213. multiple: true,
  214. // 显示搜索条件
  215. showSearch: true,
  216. // 总条数
  217. total: 0,
  218. // 设备信息表格数据
  219. deviceInfoList: [],
  220. // 公司信息表格数据
  221. companyList: [],
  222. // 公司员工信息表格数据
  223. companyUserList: [],
  224. doctorList:[],
  225. // 弹出层标题
  226. title: "",
  227. // 是否显示弹出层
  228. open: false,
  229. // 查询参数
  230. queryParams: {
  231. pageNum: 1,
  232. pageSize: 10,
  233. companyId: null,
  234. deviceNumber: null,
  235. battery: null,
  236. rssi: null,
  237. status: null,
  238. lifeStatus: undefined
  239. },
  240. // 表单参数
  241. form: {
  242. companyId: '',
  243. companyUserId:"",
  244. doctorId:"",
  245. deviceNumber: '',
  246. battery: '',
  247. rssi: '',
  248. status: 1,
  249. },
  250. // 表单校验
  251. rules: {
  252. // companyId: [
  253. // { required: true, message: "请选择所属公司", trigger: "change" }
  254. // ],
  255. deviceNumber: [
  256. { required: true, message: "设备编号不能为空", trigger: "blur" },
  257. { pattern: /^\d{15}$/, message: "设备编号必须是15位数字", trigger: "blur" }
  258. ],
  259. },
  260. sendRules:{
  261. title: [
  262. { required: true, message: '标题不能为空', trigger: 'blur' },
  263. { max: 15, message: '标题最多15个字节', trigger: 'blur' }
  264. ],
  265. description: [
  266. { required: true, message: '详情不能为空', trigger: 'blur' },
  267. { max: 240, message: '详情最多240个字节', trigger: 'blur' }
  268. ]
  269. },
  270. options: [{
  271. value: '0',
  272. label: 'OFFLINE'
  273. }, {
  274. value: '1',
  275. label: 'ONLINE'
  276. }, {
  277. value: '2',
  278. label: 'UNACTIVE'
  279. }, {
  280. value: '3',
  281. label: 'DISABLE'
  282. }, {
  283. value: '4',
  284. label: 'NOT EXIST'
  285. }],
  286. lifeStatusOptions:[{
  287. value: '0',
  288. label: '空置'
  289. },{
  290. value: '1',
  291. label: '已送出'
  292. },{
  293. value: '2',
  294. label: '已激活'
  295. }],
  296. // 是否展示设置按钮面板
  297. // showSettingBtn: true,
  298. showSend:false,
  299. senFormTitle:'',
  300. sendForm:{
  301. title:'',
  302. description:''
  303. },
  304. };
  305. },
  306. created() {
  307. this.getList();
  308. },
  309. computed: {
  310. // 计算属性来控制按钮的disabled状态
  311. sendMsgButtonDisabled() {
  312. return this.deviceNumbers.length === 0;
  313. }
  314. },
  315. methods: {
  316. rowClassName({row}) {
  317. if (row.status && row.status.includes('偏')) {
  318. // console.log("=============================" + JSON.stringify(row.status, null, 2))
  319. return 'text-red';
  320. // return true
  321. }
  322. return '';
  323. },
  324. showHealthData(deviceId) {
  325. // 模拟获取最新健康数据,实际应用中可能需要通过 API 获取数据
  326. queryLastHealthData({deviceId}).then(response => {
  327. this.selectedHealthData = response.data;
  328. });
  329. this.healthDataDialogVisible = true; // 显示弹窗
  330. },
  331. shouldShowCompanySelect() {
  332. // 根据登录用户信息判断是否显示所属公司选择框
  333. const roles = this.$store.getters.roles; // 获取角色信息
  334. // 只有包含 'admin' 或 'common' 才返回 true
  335. return (roles.includes('admin') || roles.includes('common'));
  336. },
  337. load() {
  338. if (this.hasMore) this.refreshPageAlarm()
  339. },
  340. markAllAsRead() {
  341. // 提取所有通知的 ID
  342. const ids = this.alarmData.map(notification => notification.id);
  343. // 调用 setStatus 方法将这些通知标记为已读
  344. setStatus(ids).then(response => {
  345. if (response.code == 200) {
  346. this.alarmData = this.alarmData.map(item => ({
  347. ...item,
  348. status: 1
  349. }))
  350. }
  351. })
  352. .catch(error => {
  353. console.error('一键已读操作失败:', error);
  354. });
  355. },
  356. //设置已读
  357. readItem(notification) {
  358. if (notification.status == 1) return
  359. setStatus([notification.id]).then(response => {
  360. if (response.code == 200) {
  361. notification.status = 1
  362. }
  363. })
  364. .catch(error => {
  365. console.error('更新状态失败:', error);
  366. });
  367. },
  368. getAlarm() {
  369. queryAlarm(null).then(response => {
  370. this.alarmData = response.data
  371. });
  372. },
  373. refreshPageAlarm() {
  374. this.alarmData = []
  375. this.queryAlarmParams.pageNum = 1
  376. this.hasMore = true
  377. this.getPageAlarm()
  378. },
  379. // 获取分页预警通知
  380. getPageAlarm() {
  381. queryPageAlarm(this.queryAlarmParams).then(response => {
  382. if (response.code == 200) {
  383. const list = response.rows
  384. this.alarmTotal = response.total
  385. this.alarmData = this.alarmData.concat(list)
  386. this.queryAlarmParams.pageNum++
  387. if (this.alarmData.length == this.alarmTotal) {
  388. this.hasMore = false
  389. }
  390. }
  391. });
  392. },
  393. // 查看预警通知详情
  394. goDetailPage(row) {
  395. // 如果sos跳转地图
  396. if (row.extra == "sos") {
  397. }
  398. },
  399. /** 处理查询详情按钮点击事件 */
  400. handleDetails(deviceId,userId,type) {
  401. this.$router.push({ name: 'details', params: { deviceId:deviceId,userId:userId,selectType:type } });
  402. },
  403. /** 查询设备信息列表 */
  404. getList() {
  405. this.loading = true;
  406. myDeviceInfo(this.queryParams).then(response => {
  407. this.deviceInfoList = response.rows;
  408. this.total = response.total;
  409. this.loading = false;
  410. });
  411. },
  412. // 取消按钮
  413. cancel() {
  414. this.open = false;
  415. this.reset();
  416. },
  417. // 表单重置
  418. reset() {
  419. this.form = {
  420. deviceId: null,
  421. createTime: null,
  422. createBy: null,
  423. updateTime: null,
  424. updateBy: null,
  425. companyName: null,
  426. companyId: '',
  427. companyUserId: '',
  428. deviceNumber: null,
  429. battery: null,
  430. rssi: null,
  431. status: 0
  432. };
  433. this.resetForm("form");
  434. },
  435. /** 搜索按钮操作 */
  436. handleQuery() {
  437. this.queryParams.pageNum = 1;
  438. this.getList();
  439. },
  440. /** 重置按钮操作 */
  441. resetQuery() {
  442. this.resetForm("queryForm");
  443. this.handleQuery();
  444. },
  445. // 多选框选中数据
  446. handleSelectionChange(selection) {
  447. this.ids = selection.map(item => item.deviceId)
  448. this.deviceNumbers = selection.map(item => item.deviceNumber)
  449. this.single = selection.length !== 1
  450. this.multiple = !selection.length
  451. },
  452. /** 发送消息 */
  453. sendMsg() {
  454. console.log("点击事件触发,item 为:", this.deviceNumbers);
  455. this.showSend=true;
  456. this.senFormTitle = "看课提醒";
  457. this.sendForm.title ="看课提醒";
  458. },
  459. submitSendForm(){
  460. // 首先调用表单验证方法
  461. this.$refs.sendForm.validate((valid) => {
  462. if (valid) {
  463. // 如果验证通过,则发送消息
  464. console.log("=============================2" +JSON.stringify( this.sendForm, null, 2));
  465. messageSend({
  466. deviceNumber: this.deviceNumbers.join(","),
  467. title: this.sendForm.title,
  468. description: this.sendForm.description,
  469. type: 'study'
  470. }).then(response => {
  471. if(response.code === 200){
  472. this.msgSuccess("发送成功");
  473. this.showSend = false;
  474. }
  475. });
  476. } else {
  477. // 如果验证失败,则提示用户
  478. console.log('表单验证失败');
  479. this.$message.error('请检查表单内容');
  480. return false;
  481. }
  482. });
  483. },
  484. /** 导出按钮操作 */
  485. handleExport() {
  486. const queryParams = this.queryParams;
  487. this.$confirm('是否确认导出所有设备信息数据项?', "警告", {
  488. confirmButtonText: "确定",
  489. cancelButtonText: "取消",
  490. type: "warning"
  491. }).then(() => {
  492. this.exportLoading = true;
  493. return exportMy(queryParams);
  494. }).then(response => {
  495. this.download(response.msg);
  496. this.exportLoading = false;
  497. }).catch(() => { });
  498. },
  499. // 查询紧急联系人
  500. handleSoSPeople(deviceId) {
  501. this.sosLoading = true;
  502. querySos({deviceId: deviceId}).then(res=>{
  503. this.sosLoading = false
  504. this.sosPeopleList = res.data || []
  505. this.sosVisible = true
  506. }).catch(()=>{
  507. this.sosLoading = false
  508. })
  509. }
  510. }
  511. };
  512. </script>
  513. <style>
  514. .text-red {
  515. color: red;
  516. }
  517. </style>
  518. <style lang="scss" scoped>
  519. .notification-container {
  520. padding: 10px 0;
  521. height: 80vh;
  522. overflow-y: auto;
  523. }
  524. .notification-container::-webkit-scrollbar {
  525. width: 4px;
  526. /* 设置纵轴(y轴)轴滚动条 */
  527. height: 4px;
  528. /* 设置横轴(x轴)轴滚动条 */
  529. }
  530. /* 滚动条滑块(里面小方块) */
  531. .notification-container::-webkit-scrollbar-thumb {
  532. border-radius: 10px;
  533. background: rgba(144, 147, 153, 0.3);
  534. }
  535. /* 滚动条轨道 */
  536. .notification-container::-webkit-scrollbar-track {
  537. border-radius: 0;
  538. }
  539. .notification-card {
  540. position: relative;
  541. padding-right: 10px;
  542. margin-bottom: 10px;
  543. cursor: pointer;
  544. &:hover {
  545. background: #edf8ff;
  546. }
  547. }
  548. .red-dot {
  549. position: absolute;
  550. top: 10px;
  551. right: 10px;
  552. width: 8px;
  553. height: 8px;
  554. background-color: red;
  555. border-radius: 50%;
  556. }
  557. .notification-title {
  558. font-weight: bold;
  559. font-size: 16px;
  560. }
  561. .notification-desc {
  562. margin-top: 5px;
  563. color: #666;
  564. }
  565. .notification-time {
  566. margin-top: 10px;
  567. font-size: 12px;
  568. color: #999;
  569. }
  570. .notification-status {
  571. display: flex;
  572. align-items: center;
  573. justify-content: flex-end;
  574. }
  575. .clearfix::after {
  576. content: "";
  577. display: table;
  578. clear: both;
  579. }
  580. .text {
  581. font-size: 14px;
  582. }
  583. .item {
  584. margin-bottom: 18px;
  585. }
  586. .clearfix:before,
  587. .clearfix:after {
  588. display: table;
  589. content: "";
  590. }
  591. .clearfix:after {
  592. clear: both
  593. }
  594. .box-card {
  595. width: 480px;
  596. }
  597. </style>