| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- <template>
- <wrapper
- fill
- margin
- padding
- background
- >
- <c-table
- :options="options"
- @pagination="getList"
- >
- <template #header>
- <div class="l-flex__auto c-sibling-item">
- <button
- class="o-button"
- @click="onAdd"
- >
- <i class="o-button__icon el-icon-circle-plus-outline" />
- 新增
- </button>
- </div>
- <search-input
- v-model.trim="options.params.name"
- class="l-flex__none c-sibling-item"
- placeholder="分组名称"
- @search="search"
- />
- <button
- class="l-flex__none c-sibling-item o-button"
- @click="search"
- >
- 搜索
- </button>
- </template>
- <el-table-column
- prop="name"
- label="分类名称"
- align="center"
- />
- <el-table-column
- prop="remark"
- label="备注"
- align="center"
- show-overflow-tooltip
- />
- <el-table-column
- label="操作"
- align="center"
- width="240"
- >
- <template v-slot="scope">
- <div
- class="c-table__btn u-pointer"
- @click="onEdit(scope.row)"
- >
- 编辑
- </div>
- <div
- class="c-table__btn u-pointer"
- @click="onViewDevices(scope.row)"
- >
- 设备
- </div>
- <div
- class="c-table__btn u-pointer"
- @click="onDel(scope.row)"
- >
- 删除
- </div>
- </template>
- </el-table-column>
- </c-table>
- <confirm-dialog
- ref="editDialog"
- :title="dialogTitle"
- @confirm="onSave"
- >
- <div class="c-form">
- <div class="c-form__section required">
- <span class="c-form__label required">名称:</span>
- <el-input
- v-model.trim="currObj.name"
- class="c-form__item"
- maxlength="50"
- />
- </div>
- <div class="c-form__section">
- <span class="c-form__label">备注:</span>
- <el-input
- v-model="currObj.remark"
- class="c-form__item"
- type="textarea"
- maxlength="100"
- />
- </div>
- </div>
- </confirm-dialog>
- <el-dialog
- title="设备"
- :visible.sync="showGroupDevices"
- custom-class="c-dialog large"
- >
- <c-table
- :options="groupOptions"
- @pagination="getDevicesByGroup"
- >
- <template #header>
- <button
- class="o-button"
- @click="onDevice"
- >
- <i class="o-button__icon el-icon-circle-plus-outline" />
- 添加设备
- </button>
- </template>
- <el-table-column
- prop="name"
- label="设备名称"
- align="center"
- show-overflow-tooltip
- />
- <el-table-column
- prop="productName"
- label="产品"
- align="center"
- show-overflow-tooltip
- />
- <el-table-column
- prop="serialNumber"
- label="序列号"
- align="center"
- show-overflow-tooltip
- />
- <el-table-column
- prop="mac"
- label="MAC"
- align="center"
- show-overflow-tooltip
- />
- <el-table-column
- prop="resolutionRatio"
- label="分辨率"
- align="center"
- width="120"
- />
- <el-table-column
- label="操作"
- align="center"
- width="80"
- >
- <template v-slot="scope">
- <div
- class="c-table__btn u-pointer"
- @click="delDeviceFromGroup(scope.row, scope.$index)"
- >
- 移除
- </div>
- </template>
- </el-table-column>
- </c-table>
- </el-dialog>
- <el-dialog
- title="添加设备"
- :visible.sync="showDevices"
- custom-class="c-dialog large"
- append-to-body
- >
- <c-table
- :options="deviceOptions"
- @pagination="getDevices"
- @row-dblclick="chooseDevice"
- >
- <template #header>
- <div class="l-flex__auto" />
- <search-input
- v-model.trim="deviceOptions.params.name"
- class="l-flex__none c-sibling-item"
- placeholder="设备名称"
- @search="searchDevices"
- />
- <button
- class="l-flex__none c-sibling-item o-button"
- @click="searchDevices"
- >
- 搜索
- </button>
- </template>
- <el-table-column
- prop="name"
- label="设备名称"
- align="center"
- show-overflow-tooltip
- />
- <el-table-column
- prop="productName"
- label="产品"
- align="center"
- show-overflow-tooltip
- />
- <el-table-column
- prop="serialNumber"
- label="序列号"
- align="center"
- show-overflow-tooltip
- />
- <el-table-column
- prop="mac"
- label="MAC"
- align="center"
- show-overflow-tooltip
- />
- <el-table-column
- prop="resolutionRatio"
- label="分辨率"
- align="center"
- width="120"
- />
- <el-table-column
- prop="remark"
- label="备注"
- align="center"
- show-overflow-tooltip
- />
- </c-table>
- </el-dialog>
- </wrapper>
- </template>
- <script>
- import {
- getDeviceGroups,
- addDeviceGroup,
- updateDeviceGroup,
- deleteDeviceGroup,
- getDevicesByGroup,
- getDevices,
- addDeviceToGroup,
- deleteDeviceFromGroup
- } from '@/api/device'
- import { createListOptions } from '@/utils'
- import mixin from '../mixins'
- export default {
- name: 'DeviceGroup',
- mixins: [mixin],
- data () {
- return {
- type: '分组',
- proxy: {
- list: getDeviceGroups,
- add: addDeviceGroup,
- update: updateDeviceGroup,
- del: deleteDeviceGroup
- },
- options: createListOptions({ name: '' }),
- showGroupDevices: false,
- groupOptions: {
- list: [],
- loading: false,
- error: false
- },
- showDevices: false,
- deviceOptions: createListOptions()
- }
- },
- created () {
- this.getList()
- },
- methods: {
- onSave (done) {
- if (!this.currObj.name) {
- this.$message({
- type: 'warning',
- message: '名称不能为空'
- })
- return false
- }
- this.save(done)
- },
- afterAdd () {
- const params = this.options.params
- if (params.name && !(new RegExp(params.name).test(this.currObj.name))) {
- params.name = ''
- }
- },
- onViewDevices ({ id }) {
- this.groupOptions = {
- id,
- list: [],
- loading: false,
- error: false
- }
- this.getDevicesByGroup()
- this.showGroupDevices = true
- },
- getDevicesByGroup () {
- const options = this.groupOptions
- options.error = false
- options.loading = true
- getDevicesByGroup(options.id).then(({ data, totalCount }) => {
- options.list = data
- }, () => {
- options.error = true
- options.list = []
- }).finally(() => {
- options.loading = false
- })
- },
- delDeviceFromGroup (device, index) {
- const options = this.groupOptions
- deleteDeviceFromGroup(options.id, device).then(() => {
- options.list.splice(index, 1)
- })
- },
- onDevice () {
- this.getDevices()
- this.showDevices = true
- },
- searchDevices () {
- this.deviceOptions.list = []
- this.deviceOptions.totalCount = 0
- this.deviceOptions.params.pageNum = 1
- this.getDevices()
- },
- getDevices () {
- const options = this.deviceOptions
- options.error = false
- options.loading = true
- getDevices(options.params).then(({ data, totalCount }) => {
- options.list = data
- options.totalCount = totalCount
- }, () => {
- options.error = true
- options.list = []
- }).finally(() => {
- options.loading = false
- })
- },
- chooseDevice (item) {
- addDeviceToGroup(this.groupOptions.id, item.id).then(() => {
- this.groupOptions.list = []
- this.getDevicesByGroup()
- this.showDevices = false
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- </style>
|