index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <template>
  2. <wrapper
  3. fill
  4. margin
  5. padding
  6. background
  7. >
  8. <c-table
  9. :options="options"
  10. @pagination="getList"
  11. >
  12. <template #header>
  13. <div class="l-flex__auto c-sibling-item">
  14. <button
  15. class="o-button"
  16. @click="onAdd"
  17. >
  18. <i class="o-button__icon el-icon-circle-plus-outline" />
  19. 新增
  20. </button>
  21. </div>
  22. <search-input
  23. v-model.trim="options.params.name"
  24. class="l-flex__none c-sibling-item"
  25. placeholder="分组名称"
  26. @search="search"
  27. />
  28. <button
  29. class="l-flex__none c-sibling-item o-button"
  30. @click="search"
  31. >
  32. 搜索
  33. </button>
  34. </template>
  35. <el-table-column
  36. prop="name"
  37. label="分类名称"
  38. align="center"
  39. />
  40. <el-table-column
  41. prop="remark"
  42. label="备注"
  43. align="center"
  44. show-overflow-tooltip
  45. />
  46. <el-table-column
  47. label="操作"
  48. align="center"
  49. width="240"
  50. >
  51. <template v-slot="scope">
  52. <div
  53. class="c-table__btn u-pointer"
  54. @click="onEdit(scope.row)"
  55. >
  56. 编辑
  57. </div>
  58. <div
  59. class="c-table__btn u-pointer"
  60. @click="onViewDevices(scope.row)"
  61. >
  62. 设备
  63. </div>
  64. <div
  65. class="c-table__btn u-pointer"
  66. @click="onDel(scope.row)"
  67. >
  68. 删除
  69. </div>
  70. </template>
  71. </el-table-column>
  72. </c-table>
  73. <confirm-dialog
  74. ref="editDialog"
  75. :title="dialogTitle"
  76. @confirm="onSave"
  77. >
  78. <div class="c-form">
  79. <div class="c-form__section required">
  80. <span class="c-form__label required">名称:</span>
  81. <el-input
  82. v-model.trim="currObj.name"
  83. class="c-form__item"
  84. maxlength="50"
  85. />
  86. </div>
  87. <div class="c-form__section">
  88. <span class="c-form__label">备注:</span>
  89. <el-input
  90. v-model="currObj.remark"
  91. class="c-form__item"
  92. type="textarea"
  93. maxlength="100"
  94. />
  95. </div>
  96. </div>
  97. </confirm-dialog>
  98. <el-dialog
  99. title="设备"
  100. :visible.sync="showGroupDevices"
  101. custom-class="c-dialog large"
  102. >
  103. <c-table
  104. :options="groupOptions"
  105. @pagination="getDevicesByGroup"
  106. >
  107. <template #header>
  108. <button
  109. class="o-button"
  110. @click="onDevice"
  111. >
  112. <i class="o-button__icon el-icon-circle-plus-outline" />
  113. 添加设备
  114. </button>
  115. </template>
  116. <el-table-column
  117. prop="name"
  118. label="设备名称"
  119. align="center"
  120. show-overflow-tooltip
  121. />
  122. <el-table-column
  123. prop="productName"
  124. label="产品"
  125. align="center"
  126. show-overflow-tooltip
  127. />
  128. <el-table-column
  129. prop="serialNumber"
  130. label="序列号"
  131. align="center"
  132. show-overflow-tooltip
  133. />
  134. <el-table-column
  135. prop="mac"
  136. label="MAC"
  137. align="center"
  138. show-overflow-tooltip
  139. />
  140. <el-table-column
  141. prop="resolutionRatio"
  142. label="分辨率"
  143. align="center"
  144. width="120"
  145. />
  146. <el-table-column
  147. label="操作"
  148. align="center"
  149. width="80"
  150. >
  151. <template v-slot="scope">
  152. <div
  153. class="c-table__btn u-pointer"
  154. @click="delDeviceFromGroup(scope.row, scope.$index)"
  155. >
  156. 移除
  157. </div>
  158. </template>
  159. </el-table-column>
  160. </c-table>
  161. </el-dialog>
  162. <el-dialog
  163. title="添加设备"
  164. :visible.sync="showDevices"
  165. custom-class="c-dialog large"
  166. append-to-body
  167. >
  168. <c-table
  169. :options="deviceOptions"
  170. @pagination="getDevices"
  171. @row-dblclick="chooseDevice"
  172. >
  173. <template #header>
  174. <div class="l-flex__auto" />
  175. <search-input
  176. v-model.trim="deviceOptions.params.name"
  177. class="l-flex__none c-sibling-item"
  178. placeholder="设备名称"
  179. @search="searchDevices"
  180. />
  181. <button
  182. class="l-flex__none c-sibling-item o-button"
  183. @click="searchDevices"
  184. >
  185. 搜索
  186. </button>
  187. </template>
  188. <el-table-column
  189. prop="name"
  190. label="设备名称"
  191. align="center"
  192. show-overflow-tooltip
  193. />
  194. <el-table-column
  195. prop="productName"
  196. label="产品"
  197. align="center"
  198. show-overflow-tooltip
  199. />
  200. <el-table-column
  201. prop="serialNumber"
  202. label="序列号"
  203. align="center"
  204. show-overflow-tooltip
  205. />
  206. <el-table-column
  207. prop="mac"
  208. label="MAC"
  209. align="center"
  210. show-overflow-tooltip
  211. />
  212. <el-table-column
  213. prop="resolutionRatio"
  214. label="分辨率"
  215. align="center"
  216. width="120"
  217. />
  218. <el-table-column
  219. prop="remark"
  220. label="备注"
  221. align="center"
  222. show-overflow-tooltip
  223. />
  224. </c-table>
  225. </el-dialog>
  226. </wrapper>
  227. </template>
  228. <script>
  229. import {
  230. getDeviceGroups,
  231. addDeviceGroup,
  232. updateDeviceGroup,
  233. deleteDeviceGroup,
  234. getDevicesByGroup,
  235. getDevices,
  236. addDeviceToGroup,
  237. deleteDeviceFromGroup
  238. } from '@/api/device'
  239. import { createListOptions } from '@/utils'
  240. import mixin from '../mixins'
  241. export default {
  242. name: 'DeviceGroup',
  243. mixins: [mixin],
  244. data () {
  245. return {
  246. type: '分组',
  247. proxy: {
  248. list: getDeviceGroups,
  249. add: addDeviceGroup,
  250. update: updateDeviceGroup,
  251. del: deleteDeviceGroup
  252. },
  253. options: createListOptions({ name: '' }),
  254. showGroupDevices: false,
  255. groupOptions: {
  256. list: [],
  257. loading: false,
  258. error: false
  259. },
  260. showDevices: false,
  261. deviceOptions: createListOptions()
  262. }
  263. },
  264. created () {
  265. this.getList()
  266. },
  267. methods: {
  268. onSave (done) {
  269. if (!this.currObj.name) {
  270. this.$message({
  271. type: 'warning',
  272. message: '名称不能为空'
  273. })
  274. return false
  275. }
  276. this.save(done)
  277. },
  278. afterAdd () {
  279. const params = this.options.params
  280. if (params.name && !(new RegExp(params.name).test(this.currObj.name))) {
  281. params.name = ''
  282. }
  283. },
  284. onViewDevices ({ id }) {
  285. this.groupOptions = {
  286. id,
  287. list: [],
  288. loading: false,
  289. error: false
  290. }
  291. this.getDevicesByGroup()
  292. this.showGroupDevices = true
  293. },
  294. getDevicesByGroup () {
  295. const options = this.groupOptions
  296. options.error = false
  297. options.loading = true
  298. getDevicesByGroup(options.id).then(({ data, totalCount }) => {
  299. options.list = data
  300. }, () => {
  301. options.error = true
  302. options.list = []
  303. }).finally(() => {
  304. options.loading = false
  305. })
  306. },
  307. delDeviceFromGroup (device, index) {
  308. const options = this.groupOptions
  309. deleteDeviceFromGroup(options.id, device).then(() => {
  310. options.list.splice(index, 1)
  311. })
  312. },
  313. onDevice () {
  314. this.getDevices()
  315. this.showDevices = true
  316. },
  317. searchDevices () {
  318. this.deviceOptions.list = []
  319. this.deviceOptions.totalCount = 0
  320. this.deviceOptions.params.pageNum = 1
  321. this.getDevices()
  322. },
  323. getDevices () {
  324. const options = this.deviceOptions
  325. options.error = false
  326. options.loading = true
  327. getDevices(options.params).then(({ data, totalCount }) => {
  328. options.list = data
  329. options.totalCount = totalCount
  330. }, () => {
  331. options.error = true
  332. options.list = []
  333. }).finally(() => {
  334. options.loading = false
  335. })
  336. },
  337. chooseDevice (item) {
  338. addDeviceToGroup(this.groupOptions.id, item.id).then(() => {
  339. this.groupOptions.list = []
  340. this.getDevicesByGroup()
  341. this.showDevices = false
  342. })
  343. }
  344. }
  345. }
  346. </script>
  347. <style lang="scss" scoped>
  348. </style>