index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <template>
  2. <div class='app-container'>
  3. <el-button type="primary" icon="el-icon-plus" size="mini" @click="getDialog()"
  4. v-hasPermi="['operation:channels:add']">新增多频多台</el-button>
  5. <el-table :data="tableData" v-loading="loading">
  6. <el-table-column label="频道名称" align="center" prop="name" />
  7. <el-table-column label="设备" align="center">
  8. <template slot-scope="scope">
  9. <span v-for="(item, index) in scope.row.deviceList" :key="item.clientTypeId">
  10. <span>{{ item.name }}</span>
  11. <span v-show="index + 1 !== scope.row.deviceList.length">,</span>
  12. </span>
  13. </template>
  14. </el-table-column>
  15. <el-table-column label="操作" align="center">
  16. <template slot-scope="scope">
  17. <el-button type="text" @click="getDialog(scope.row, true)">查看</el-button>
  18. <el-button type="text" @click="getDialog(scope.row)" v-hasPermi="['operation:channels:edit']">编辑</el-button>
  19. <el-button type="delete" @click="getRemove(scope.row)"
  20. v-hasPermi="['operation:channels:delete']">删除</el-button>
  21. </template>
  22. </el-table-column>
  23. </el-table>
  24. <!-- 弹窗 -->
  25. <el-dialog :visible.sync="dialogVisible" :title="title" width="1000px" :before-close="getClose">
  26. <el-form :model="dialogForm" ref="dialogForm" :rules="rules" label-width="auto">
  27. <el-form-item label="频道名称:" prop="name" style="width: 300px">
  28. <el-input v-model="dialogForm.name" placeholder="请输入规则名称" :disabled="readOnly" />
  29. </el-form-item>
  30. <el-form-item label="关联设备:" prop="deviceIds">
  31. <el-select v-model="dialogForm.deviceIds" filterable multiple placeholder="请选择关联设备" :disabled="readOnly">
  32. <el-option v-for="item in devOptions" :key="item.clientTypeId" :value="item.clientTypeId"
  33. :label="item.name" />
  34. </el-select>
  35. </el-form-item>
  36. <el-form-item v-if="dialogForm.id" label="个人频道分类:">
  37. <div class="classList" v-if="readOnly">
  38. <el-button v-for="item in dialogForm.personalChannelList" :key="item.channelTypeId"
  39. :type="active === item.sort ? 'primary' : ''" size="small" @click="getActive(item)">
  40. {{ item.channelTypeName }}
  41. </el-button>
  42. </div>
  43. <div class="classList" v-else>
  44. <!-- isFix:0 不可以编辑删除 -->
  45. <el-button v-for="item in dialogForm.personalChannelList.filter(i => i.isFix === 0)"
  46. :key="item.channelTypeId" size="small" @click="getActive(item)">
  47. {{ item.channelTypeName }}
  48. </el-button>
  49. <!-- isFix:1 可以编辑删除 -->
  50. <el-dropdown v-for="item in dialogForm.personalChannelList.filter(i => i.isFix === 1)"
  51. :key="item.channelTypeId">
  52. <el-button :type="active === item.sort ? 'primary' : ''" size="small" @click="getActive(item)">
  53. {{ item.channelTypeName }}<i class="el-icon-arrow-down" style="margin-left: 10px;" />
  54. </el-button>
  55. <el-dropdown-menu slot="dropdown">
  56. <el-dropdown-item>
  57. <div @click="getInputDialog(item)">编辑</div>
  58. </el-dropdown-item>
  59. <el-dropdown-item>
  60. <div @click="getDelete(item)">删除</div>
  61. </el-dropdown-item>
  62. </el-dropdown-menu>
  63. </el-dropdown>
  64. <el-button v-if="dialogForm.personalChannelList.length < 9" icon="el-icon-plus" size="small"
  65. @click="inputVisible = true, type = 0">新增</el-button>
  66. </div>
  67. </el-form-item>
  68. <el-form-item v-if="dialogForm.id" label="其他频道分类:">
  69. <div class="classList" v-if="readOnly">
  70. <el-button v-for="item in dialogForm.otherChannelList" :key="item.channelTypeId"
  71. :type="active === item.sort ? 'primary' : ''" size="small" @click="getActive(item)">
  72. {{ item.channelTypeName }}
  73. </el-button>
  74. </div>
  75. <div class="classList" v-else>
  76. <el-dropdown v-for="item in dialogForm.otherChannelList" :key="item.channelTypeId">
  77. <el-button :type="active === item.sort ? 'primary' : ''" size="small" @click="getActive(item)">
  78. {{ item.channelTypeName }}<i class="el-icon-arrow-down" style="margin-left: 10px;" />
  79. </el-button>
  80. <el-dropdown-menu slot="dropdown">
  81. <el-dropdown-item>
  82. <div @click="getInputDialog(item)">编辑</div>
  83. </el-dropdown-item>
  84. <el-dropdown-item>
  85. <div @click="getDelete(item)">删除</div>
  86. </el-dropdown-item>
  87. </el-dropdown-menu>
  88. </el-dropdown>
  89. <el-button icon="el-icon-plus" size="small" @click="inputVisible = true, type = 1">新增</el-button>
  90. </div>
  91. </el-form-item>
  92. </el-form>
  93. <el-table v-show="dialogForm.id" :data="dialogForm.defaultList">
  94. <el-table-column label="频道号" align="center" prop="channelId" width="75px" />
  95. <el-table-column label="频道名称" align="center" prop="aliasName" show-overflow-tooltip />
  96. <el-table-column label="频道封面" align="center" width="100px">
  97. <template slot-scope="scope">
  98. <el-image :src="scope.row.pic" />
  99. </template>
  100. </el-table-column>
  101. <el-table-column label="频道简介" align="center" prop="description" show-overflow-tooltip />
  102. <el-table-column label="操作" align="center">
  103. <template slot-scope="scope">
  104. <el-button type="text" @click="getRouter(scope, true)">查看</el-button>
  105. <el-button type="text" @click="getRouter(scope)" :disabled="readOnly">编辑</el-button>
  106. <el-button v-if="scope.row.sort > 3" type="text" icon="el-icon-caret-top"
  107. @click="getChange(scope.row, scope.row.sort - 1)" :disabled="readOnly" />
  108. <el-button v-if="scope.row.sort > 2 && scope.row.sort < 12" type="text" icon="el-icon-caret-bottom"
  109. @click="getChange(scope.row, scope.row.sort + 1)" :disabled="readOnly" />
  110. </template>
  111. </el-table-column>
  112. </el-table>
  113. <div v-if="!readOnly" slot="footer">
  114. <el-button @click="getClose">取消</el-button>
  115. <el-button type="primary" @click="getSubmit">确定</el-button>
  116. </div>
  117. </el-dialog>
  118. <el-dialog :visible.sync="inputVisible" title="分类名称" width="500px" :before-close="getInputClose">
  119. <el-input v-model="classForm.channelTypeName" placeholder="请输入分类名称" />
  120. <div slot="footer">
  121. <el-button @click="getInputClose">取消</el-button>
  122. <el-button type="primary" @click="getInputSubmit">确定</el-button>
  123. </div>
  124. </el-dialog>
  125. </div>
  126. </template>
  127. <script>
  128. import { list, dev, submit, edit, detail, change, remove, channels, classSubmit, classEdit, classRemove } from "@/api/operation/channels"
  129. export default {
  130. data() {
  131. return {
  132. // 遮罩层
  133. loading: false,
  134. // 列表
  135. tableData: [],
  136. // 全部设备列表
  137. allDevOptions: [],
  138. // 剔除已选的设备列表
  139. devOptions: [],
  140. // 弹窗
  141. dialogVisible: false,
  142. // 查看
  143. readOnly: false,
  144. // 弹窗名称
  145. title: '新增',
  146. // 弹窗表单
  147. dialogForm: {
  148. deviceIds: []
  149. },
  150. row: {},
  151. // 分类焦点
  152. active: 1,
  153. // 分类弹窗
  154. inputVisible: false,
  155. // 分类表单
  156. classForm: {},
  157. // 分类类型
  158. type: null,
  159. // 校验
  160. rules: {
  161. name: [{
  162. required: true, message: '请输入规则名称', trigger: 'blur'
  163. }],
  164. deviceIds: [{
  165. required: true, message: '请选择关联设备', trigger: 'change'
  166. }]
  167. }
  168. }
  169. },
  170. async mounted() {
  171. await this.getDev(1)
  172. this.getList()
  173. },
  174. methods: {
  175. // 列表
  176. getList() {
  177. this.loading = true
  178. list().then(res => {
  179. if (res.code === 0) {
  180. this.tableData = res.data
  181. this.loading = false
  182. }
  183. })
  184. },
  185. // 设备列表
  186. async getDev(type) {
  187. await dev(type).then(res => {
  188. if (type === 0) {
  189. this.devOptions = res.data
  190. } else {
  191. this.allDevOptions = res.data
  192. }
  193. })
  194. },
  195. // 删除频道规则
  196. getRemove(row) {
  197. this.$confirm(`是否删除${row.name}?`, '提示').then(() => {
  198. remove(row.id).then(res => {
  199. if (res.code === 0) {
  200. this.$message.success('删除成功!')
  201. this.getList()
  202. }
  203. })
  204. })
  205. },
  206. // 弹窗
  207. async getDialog(row, boolean) {
  208. this.dialogVisible = true
  209. this.readOnly = boolean
  210. await this.getDev(0)
  211. if (row !== undefined) {
  212. this.row = row
  213. this.devOptions.unshift.apply(this.devOptions, this.row.deviceList)
  214. this.getDetail()
  215. }
  216. },
  217. // 详情
  218. getDetail() {
  219. detail(this.row.id).then(res => {
  220. if (res.code === 0) {
  221. this.active = 1
  222. this.dialogForm = res.data
  223. this.dialogForm.deviceIds = res.data.deviceIds.split(',')
  224. }
  225. })
  226. },
  227. // 获取焦点
  228. getActive(item) {
  229. this.active = item.sort
  230. this.getChannels(item.channelTypeId)
  231. },
  232. // 12频道
  233. getChannels(id) {
  234. channels(id).then(res => {
  235. if (res.code === 0) {
  236. this.dialogForm.defaultList = res.data
  237. }
  238. })
  239. },
  240. // 打开分类弹窗
  241. getInputDialog(item) {
  242. this.inputVisible = true
  243. this.classForm = JSON.parse(JSON.stringify(item))
  244. },
  245. // 关闭分类表单
  246. getInputClose() {
  247. this.inputVisible = false
  248. this.classForm = {}
  249. },
  250. // 提交分类表单
  251. getInputSubmit() {
  252. if (this.classForm.name === "") {
  253. this.$message.error('请输入频道分类名称')
  254. } else {
  255. if (this.type === null) {
  256. classEdit(this.classForm.channelTypeName, this.classForm.channelTypeId).then(res => {
  257. if (res.code === 0) {
  258. this.inputVisible = false
  259. this.$message.success('编辑成功!')
  260. this.getDetail()
  261. }
  262. })
  263. } else {
  264. classSubmit(this.classForm.channelTypeName, this.type, this.dialogForm.id).then(res => {
  265. if (res.code === 0) {
  266. this.inputVisible = false
  267. this.$message.success('新增成功!')
  268. this.getDetail()
  269. }
  270. })
  271. }
  272. }
  273. },
  274. // 提交
  275. getSubmit() {
  276. this.$refs.dialogForm.validate((valid) => {
  277. if (valid) {
  278. this.dialogForm.deviceIds = this.dialogForm.deviceIds.join(',')
  279. if (this.dialogForm.id) {
  280. edit(this.dialogForm).then(res => {
  281. if (res.code === 0) {
  282. this.$message.success('编辑成功!')
  283. this.getClose()
  284. this.getList()
  285. }
  286. })
  287. } else {
  288. submit(this.dialogForm).then(res => {
  289. if (res.code === 0) {
  290. this.$message.success('提交成功!')
  291. this.getClose()
  292. this.getList()
  293. }
  294. })
  295. }
  296. } else {
  297. return false
  298. }
  299. })
  300. },
  301. // 取消
  302. getClose() {
  303. this.dialogVisible = false
  304. this.dialogForm = {}
  305. this.$refs.dialogForm.resetFields()
  306. },
  307. // 删除
  308. getDelete(item) {
  309. this.$confirm(`是否删除${item.channelTypeName}?`, '提示').then(() => {
  310. classRemove(item.channelTypeId).then(res => {
  311. if (res.code === 0) {
  312. this.$message.success('删除成功!')
  313. this.getDetail()
  314. }
  315. })
  316. }).catch(() => { })
  317. },
  318. // 12频道详情
  319. getRouter(e, boolean) {
  320. this.$router.push({
  321. path: `/operation/channels/detail`,
  322. query: {
  323. channelId: e.row.id,
  324. audioType: e.row.channelType,
  325. index: e.$index,
  326. boolean: boolean
  327. }
  328. })
  329. },
  330. // 排序
  331. getChange(row, sort) {
  332. change({
  333. id: row.id,
  334. sort: sort
  335. }).then(res => {
  336. if (res.code === 0) {
  337. this.$message.success('修改成功!')
  338. this.getChannels(row.templateCategoryId)
  339. }
  340. })
  341. },
  342. }
  343. }
  344. </script>
  345. <style lang="scss" scoped>
  346. .classList {
  347. ::v-deep .el-button {
  348. margin: 0 10px 10px 0;
  349. }
  350. }
  351. </style>