index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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.label" :value="item.value.toString()"
  35. :label="item.label" />
  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" type="text" icon="el-icon-caret-bottom"
  54. @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 = []
  167. res.data.map(i => {
  168. this.devOptions.push({
  169. value: i.clientTypeId,
  170. label: i.name
  171. })
  172. })
  173. }
  174. })
  175. if (row) {
  176. this.title = '编辑'
  177. this.dialogForm = row
  178. if (this.index !== 1) {
  179. this.ids = this.dialogForm.deviceIds.split(',')
  180. }
  181. this.getPage(row)
  182. } else {
  183. this.ids = []
  184. this.dialogForm = {}
  185. this.title = '新增'
  186. }
  187. },
  188. // 十二频道
  189. getPage(row) {
  190. channelPage(row.id).then(res => {
  191. if (res.code === 0) {
  192. this.list = res.data
  193. this.dialog_loading = false
  194. }
  195. })
  196. },
  197. // 创建
  198. getSubmit() {
  199. if (this.title === '编辑') {
  200. editPage(this.dialogForm).then(res => {
  201. if (res.code === 0) {
  202. this.$message.success('修改成功!')
  203. this.dialogVisible = false
  204. this.getList()
  205. }
  206. })
  207. } else {
  208. create({
  209. name: this.dialogForm.name,
  210. deviceIds: this.dialogForm.deviceIds,
  211. type: 1
  212. }).then(res => {
  213. if (res.code === 0) {
  214. this.$message.success('新增成功!')
  215. this.dialogVisible = false
  216. this.getList()
  217. }
  218. })
  219. }
  220. },
  221. // 排序
  222. getChange(id, sort) {
  223. change({
  224. id: id,
  225. sort: sort
  226. }).then(res => {
  227. if (res.code === 0) {
  228. this.$message.success('修改成功!')
  229. this.getPage(this.obj)
  230. }
  231. })
  232. },
  233. // 取消
  234. cancel() {
  235. this.dialogVisible = false
  236. this.getList()
  237. },
  238. // 字典翻译
  239. typeFormatter(row) {
  240. return this.selectDictLabel(this.dict.type.deployment_form, row.type)
  241. },
  242. devFormatter(row) {
  243. return row.deviceIds ? row.deviceIds.split(',').map(i => this.selectDictLabel(this.allDevOptions, i)).join(',') : ''
  244. }
  245. },
  246. };
  247. </script>