index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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"
  14. show-overflow-tooltip />
  15. <el-table-column label="操作" align="center">
  16. <template slot-scope="scope">
  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">
  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="请输入规则名称" />
  31. </el-form-item>
  32. <el-form-item v-if="index !== 1" label="关联设备:">
  33. <el-select v-model="ids" multiple placeholder="请选择关联设备">
  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="内容列表:">
  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="aliasName" align="center" show-overflow-tooltip />
  42. <el-table-column label="频道封面" align="center" width="100px">
  43. <template slot-scope="scope">
  44. <el-image :src="scope.row.pic"></el-image>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="频道简介" prop="description" align="center" show-overflow-tooltip />
  48. <el-table-column label="操作" align="center">
  49. <template slot-scope="scope">
  50. <el-button type="text" @click="edit(scope)">编辑</el-button>
  51. <el-button v-if="scope.row.sort > 3" type="text" icon="el-icon-caret-top"
  52. @click="getChange(scope.row.id, scope.row.sort - 1)" />
  53. <el-button v-if="scope.row.sort > 2 && scope.row.sort < 12" type="text"
  54. icon="el-icon-caret-bottom" @click="getChange(scope.row.id, scope.row.sort + 1)" />
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. </el-form-item>
  59. </el-form>
  60. <div slot="footer" v-if="index !== 1">
  61. <el-button @click="cancel">取消</el-button>
  62. <el-button type="primary" @click="getSubmit">确定</el-button>
  63. </div>
  64. </el-dialog>
  65. </div>
  66. </template>
  67. <script>
  68. import { channelPage, page, create, editPage, getRemove, devList, change } from '@/api/operation/channel'
  69. export default {
  70. name: 'Channel',
  71. dicts: ['deployment_form'],
  72. data() {
  73. return {
  74. // 遮罩层
  75. loading: false,
  76. dialog_loading: false,
  77. // 列表
  78. tableData: [],
  79. list: [],
  80. // 弹窗
  81. dialogVisible: false,
  82. title: '',
  83. // 设备
  84. devOptions: [],
  85. allDevOptions: [],
  86. // 表单
  87. form: {
  88. pageNum: 1,
  89. pageSize: 10
  90. },
  91. index: 0,
  92. dialogForm: {},
  93. ids: [],
  94. // 频道规则Id
  95. obj: {}
  96. };
  97. },
  98. watch: {
  99. ids(val) {
  100. this.dialogForm.deviceIds = val.join(',')
  101. }
  102. },
  103. mounted() {
  104. this.getDevList()
  105. this.getList()
  106. },
  107. methods: {
  108. // 列表
  109. getList() {
  110. this.loading = true
  111. page(this.form).then(res => {
  112. if (res.code === 0) {
  113. this.tableData = res.data
  114. this.loading = false
  115. }
  116. })
  117. },
  118. // 全部设备
  119. getDevList() {
  120. devList(1).then(res => {
  121. if (res.code === 0) {
  122. this.allDevOptions = []
  123. res.data.map(i => {
  124. this.allDevOptions.push({
  125. value: i.clientTypeId,
  126. label: i.name
  127. })
  128. })
  129. }
  130. })
  131. },
  132. // 编辑
  133. edit(e) {
  134. this.dialogVisible = false
  135. this.$router.push({
  136. path: `/operation/channel/detail`,
  137. query: {
  138. channelId: e.row.id,
  139. audioType: e.row.channelType,
  140. index: e.$index
  141. }
  142. })
  143. },
  144. // 删除
  145. getDelete(row) {
  146. this.$confirm(`是否删除${row.name}?`, '提示', {
  147. type: 'warning'
  148. }).then(() => {
  149. getRemove(row.id).then(res => {
  150. if (res.code === 0) {
  151. this.$message.success('删除成功!')
  152. this.getList()
  153. }
  154. })
  155. })
  156. },
  157. // 弹窗
  158. getDialog(row, index) {
  159. this.dialogVisible = true
  160. this.index = index + 1
  161. this.obj = row
  162. // 新增 / 编辑时的设备
  163. let type = row ? 1 : 0
  164. devList(type).then(res => {
  165. if (res.code === 0) {
  166. this.devOptions = res.data
  167. }
  168. })
  169. if (row) {
  170. this.title = '编辑'
  171. this.dialogForm = row
  172. if (this.index !== 1) {
  173. this.ids = this.dialogForm.deviceIds.split(',')
  174. }
  175. this.getPage(row)
  176. } else {
  177. this.ids = []
  178. this.dialogForm = {}
  179. this.title = '新增'
  180. }
  181. },
  182. // 十二频道
  183. getPage(row) {
  184. channelPage(row.id).then(res => {
  185. if (res.code === 0) {
  186. this.list = res.data
  187. this.dialog_loading = false
  188. }
  189. })
  190. },
  191. // 创建
  192. getSubmit() {
  193. if (this.title === '编辑') {
  194. editPage(this.dialogForm).then(res => {
  195. if (res.code === 0) {
  196. this.$message.success('修改成功!')
  197. this.dialogVisible = false
  198. this.getList()
  199. }
  200. })
  201. } else {
  202. create({
  203. name: this.dialogForm.name,
  204. deviceIds: this.dialogForm.deviceIds,
  205. type: 1
  206. }).then(res => {
  207. if (res.code === 0) {
  208. this.$message.success('新增成功!')
  209. this.dialogVisible = false
  210. this.getList()
  211. }
  212. })
  213. }
  214. },
  215. // 排序
  216. getChange(id, sort) {
  217. change({
  218. id: id,
  219. sort: sort
  220. }).then(res => {
  221. if (res.code === 0) {
  222. this.$message.success('修改成功!')
  223. this.getPage(this.obj)
  224. }
  225. })
  226. },
  227. // 取消
  228. cancel() {
  229. this.dialogVisible = false
  230. this.getList()
  231. },
  232. // 字典翻译
  233. typeFormatter(row) {
  234. return this.selectDictLabel(this.dict.type.deployment_form, row.type)
  235. },
  236. devFormatter(row) {
  237. return row.deviceIds ? row.deviceIds.split(',').map(i => this.selectDictLabel(this.allDevOptions, i)).join(',') : ''
  238. }
  239. },
  240. };
  241. </script>