index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <div class="app-container">
  3. <!-- 新增 -->
  4. <el-button type="primary" icon="el-icon-plus" size="mini" @click="getDialog('新增')"
  5. v-hasPermi="['operation:channel:add']">
  6. 新增频道配置
  7. </el-button>
  8. <!-- 列表 -->
  9. <el-table :data="tableData" v-loading="loading">
  10. <el-table-column label="序号" align="center" type="index" />
  11. <el-table-column label="频道配置名称" prop="name" align="center" />
  12. <el-table-column label="部署形式" prop="type" align="center" :formatter="typeFormatter" />
  13. <el-table-column label="设备" prop="deviceIds" align="center" :formatter="devFormatter" show-overflow-tooltip />
  14. <el-table-column label="操作" align="center">
  15. <template slot-scope="scope">
  16. <el-button type="text" @click="getDialog('查看', scope.row, scope.$index, true)">查看</el-button>
  17. <el-button type="text" @click="getDialog('编辑', scope.row, scope.$index)"
  18. v-hasPermi="['operation:channel:edit']">编辑</el-button>
  19. <el-button v-if="scope.$index !== 0" type="delete" @click="getDelete(scope.row)"
  20. v-hasPermi="['operation:channel:delete']">
  21. 删除
  22. </el-button>
  23. </template>
  24. </el-table-column>
  25. </el-table>
  26. <!-- 弹窗 -->
  27. <el-dialog :visible.sync="dialogVisible" :title="title" width="950px" :before-close="cancel">
  28. <el-form label-width="auto">
  29. <el-form-item v-if="index !== 1" label="频道配置名称:" style="width: 300px">
  30. <el-input v-model="dialogForm.name" placeholder="请输入规则名称" :disabled="disabled" />
  31. </el-form-item>
  32. <el-form-item v-if="index !== 1" label="关联设备:">
  33. <el-select v-model="ids" filterable multiple placeholder="请选择关联设备" :disabled="disabled">
  34. <el-option v-for="item in devOptions" :key="item.clientTypeId" :value="item.clientTypeId.toString()"
  35. :label="item.name" />
  36. </el-select>
  37. </el-form-item>
  38. <el-form-item v-if="title !== '新增'" label="内容列表:" style="height: 500px; overflow-y: auto;">
  39. <el-table :data="list" v-loading="dialog_loading" lazy :default-sort="{ prop: 'sort' }">
  40. <el-table-column label="序号" prop="sort" align="center" width="100px" />
  41. <el-table-column label="频道数" prop="channelId" align="center" width="100px" />
  42. <el-table-column label="频道名称" prop="aliasName" align="center" show-overflow-tooltip />
  43. <el-table-column label="频道封面" align="center" width="100px">
  44. <template slot-scope="scope">
  45. <el-image :src="scope.row.pic"></el-image>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="频道简介" prop="description" align="center" show-overflow-tooltip />
  49. <el-table-column label="操作" align="center">
  50. <template slot-scope="scope">
  51. <el-button type="text" @click="edit(scope, true)">查看</el-button>
  52. <el-button type="text" @click="edit(scope)" :disabled="disabled">编辑</el-button>
  53. <el-button v-if="scope.row.sort > 3" type="text" icon="el-icon-caret-top"
  54. @click="getChange(scope.row.id, scope.row.sort - 1)" :disabled="disabled" />
  55. <el-button v-if="scope.row.sort > 2 && scope.row.sort < 12" type="text" icon="el-icon-caret-bottom"
  56. @click="getChange(scope.row.id, scope.row.sort + 1)" :disabled="disabled" />
  57. </template>
  58. </el-table-column>
  59. </el-table>
  60. </el-form-item>
  61. </el-form>
  62. <div slot="footer" v-if="index !== 1">
  63. <el-button @click="cancel">取消</el-button>
  64. <el-button type="primary" @click="getSubmit">确定</el-button>
  65. </div>
  66. </el-dialog>
  67. </div>
  68. </template>
  69. <script>
  70. import { change, channelPage, create, devList, editPage, getRemove, page } from '@/api/operation/channel';
  71. export default {
  72. name: 'Channel',
  73. data() {
  74. return {
  75. // 遮罩层
  76. loading: false,
  77. dialog_loading: false,
  78. // 列表
  79. tableData: [],
  80. list: [],
  81. // 弹窗
  82. dialogVisible: false,
  83. title: '',
  84. // 设备
  85. devOptions: [],
  86. allDevOptions: [],
  87. // 表单
  88. form: {
  89. pageNum: 1,
  90. pageSize: 10
  91. },
  92. index: 0,
  93. dialogForm: {},
  94. ids: [],
  95. // 频道规则Id
  96. obj: {},
  97. // 部署形式
  98. typeOptions: [{
  99. value: 0,
  100. label: '注册用户-默认'
  101. }, {
  102. value: 1,
  103. label: '绑定特定设备'
  104. }],
  105. // 只读
  106. disabled: false
  107. };
  108. },
  109. watch: {
  110. ids(val) {
  111. this.dialogForm.deviceIds = val.join(',')
  112. }
  113. },
  114. mounted() {
  115. this.getDevList()
  116. this.getList()
  117. },
  118. methods: {
  119. // 列表
  120. getList() {
  121. this.loading = true
  122. page(this.form).then(res => {
  123. if (res.code === 0) {
  124. this.tableData = res.data
  125. this.loading = false
  126. }
  127. })
  128. },
  129. // 全部设备
  130. getDevList() {
  131. devList(1).then(res => {
  132. if (res.code === 0) {
  133. this.allDevOptions = []
  134. res.data.map(i => {
  135. this.allDevOptions.push({
  136. value: i.clientTypeId,
  137. label: i.name
  138. })
  139. })
  140. }
  141. })
  142. },
  143. // 编辑
  144. edit(e, boolean) {
  145. this.dialogVisible = false
  146. this.$router.push({
  147. path: `/operation/channel/detail`,
  148. query: {
  149. channelId: e.row.id,
  150. audioType: e.row.channelType,
  151. index: e.$index,
  152. boolean: boolean
  153. }
  154. })
  155. },
  156. // 删除
  157. getDelete(row) {
  158. this.$confirm(`是否删除${row.name}?`, '提示', {
  159. type: 'warning'
  160. }).then(() => {
  161. getRemove(row.id).then(res => {
  162. if (res.code === 0) {
  163. this.$message.success('删除成功!')
  164. this.getList()
  165. }
  166. })
  167. })
  168. },
  169. // 弹窗
  170. getDialog(title, row, index, boolean) {
  171. this.dialogVisible = true
  172. this.title = title
  173. this.index = index + 1
  174. this.obj = row
  175. this.disabled = boolean
  176. // 新增 / 编辑时的设备
  177. devList(0).then(res => {
  178. if (res.code === 0) {
  179. this.devOptions = res.data
  180. if (this.title !== '新增') {
  181. this.devOptions.unshift.apply(this.devOptions, row.deviceList)
  182. }
  183. }
  184. })
  185. if (title !== '新增') {
  186. this.dialogForm = row
  187. if (this.index !== 1) {
  188. this.ids = this.dialogForm.deviceIds.split(',')
  189. }
  190. this.getPage(row)
  191. }
  192. },
  193. // 十二频道
  194. getPage(row) {
  195. channelPage(row.id).then(res => {
  196. if (res.code === 0) {
  197. this.list = res.data
  198. this.dialog_loading = false
  199. }
  200. })
  201. },
  202. // 创建
  203. getSubmit() {
  204. if (this.title === '编辑') {
  205. editPage(this.dialogForm).then(res => {
  206. if (res.code === 0) {
  207. this.$message.success('修改成功!')
  208. this.dialogVisible = false
  209. this.getList()
  210. }
  211. })
  212. } else {
  213. create({
  214. name: this.dialogForm.name,
  215. deviceIds: this.dialogForm.deviceIds,
  216. type: 1
  217. }).then(res => {
  218. if (res.code === 0) {
  219. this.$message.success('新增成功!')
  220. this.dialogVisible = false
  221. this.getList()
  222. }
  223. })
  224. }
  225. },
  226. // 排序
  227. getChange(id, sort) {
  228. change({
  229. id: id,
  230. sort: sort
  231. }).then(res => {
  232. if (res.code === 0) {
  233. this.$message.success('修改成功!')
  234. this.getPage(this.obj)
  235. }
  236. })
  237. },
  238. // 取消
  239. cancel() {
  240. this.dialogVisible = false
  241. this.ids = []
  242. this.dialogForm = {}
  243. this.getList()
  244. },
  245. // 字典翻译
  246. typeFormatter(row) {
  247. return this.selectDictLabel(this.typeOptions, row.type)
  248. },
  249. devFormatter(row) {
  250. return row.deviceIds ? row.deviceIds.split(',').map(i => this.selectDictLabel(this.allDevOptions, i)).join(',') : ''
  251. }
  252. },
  253. };
  254. </script>