index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <!-- 运营管理 定制频道-->
  2. <template>
  3. <div class="app-container">
  4. <!-- 新增 -->
  5. <el-button
  6. type="primary"
  7. icon="el-icon-plus"
  8. size="mini"
  9. @click="getDialog('新增')"
  10. v-hasPermi="['operation:channel:add']"
  11. >
  12. 新增频道配置
  13. </el-button>
  14. <!-- 列表 -->
  15. <el-table :data="tableData" v-loading="loading">
  16. <el-table-column label="序号" align="center" type="index" />
  17. <el-table-column label="频道配置名称" prop="name" align="center" />
  18. <el-table-column
  19. label="部署形式"
  20. prop="type"
  21. align="center"
  22. :formatter="typeFormatter"
  23. />
  24. <el-table-column
  25. label="设备"
  26. prop="deviceIds"
  27. align="center"
  28. :formatter="devFormatter"
  29. show-overflow-tooltip
  30. />
  31. <el-table-column label="操作" align="center">
  32. <template slot-scope="scope">
  33. <el-button
  34. type="text"
  35. @click="getDialog('查看', scope.row, scope.$index, true)"
  36. >查看</el-button
  37. >
  38. <el-button
  39. type="text"
  40. @click="getDialog('编辑', scope.row, scope.$index)"
  41. v-hasPermi="['operation:channel:edit']"
  42. >编辑</el-button
  43. >
  44. <el-button
  45. v-if="scope.$index !== 0"
  46. type="delete"
  47. @click="getDelete(scope.row)"
  48. v-hasPermi="['operation:channel:delete']"
  49. >
  50. 删除
  51. </el-button>
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. <!-- 弹窗 -->
  56. <el-dialog
  57. :visible.sync="dialogVisible"
  58. :title="title"
  59. width="950px"
  60. :before-close="cancel"
  61. >
  62. <el-form label-width="auto">
  63. <el-form-item
  64. v-if="index !== 1"
  65. label="频道配置名称:"
  66. style="width: 300px"
  67. >
  68. <el-input
  69. v-model="dialogForm.name"
  70. placeholder="请输入规则名称"
  71. :disabled="disabled"
  72. />
  73. </el-form-item>
  74. <el-form-item v-if="index !== 1" label="关联设备:">
  75. <el-select
  76. v-model="ids"
  77. filterable
  78. multiple
  79. placeholder="请选择关联设备"
  80. :disabled="disabled"
  81. >
  82. <el-option
  83. v-for="item in devOptions"
  84. :key="item.clientTypeId"
  85. :value="item.clientTypeId.toString()"
  86. :label="item.name"
  87. />
  88. </el-select>
  89. </el-form-item>
  90. <el-form-item
  91. v-if="title !== '新增'"
  92. label="内容列表:"
  93. style="height: 500px; overflow-y: auto"
  94. >
  95. <el-table
  96. :data="list"
  97. v-loading="dialog_loading"
  98. lazy
  99. :default-sort="{ prop: 'sort' }"
  100. >
  101. <el-table-column
  102. label="序号"
  103. prop="sort"
  104. align="center"
  105. width="100px"
  106. />
  107. <el-table-column
  108. label="频道数"
  109. prop="channelId"
  110. align="center"
  111. width="100px"
  112. />
  113. <el-table-column
  114. label="频道名称"
  115. prop="aliasName"
  116. align="center"
  117. show-overflow-tooltip
  118. />
  119. <el-table-column label="频道封面" align="center" width="100px">
  120. <template slot-scope="scope">
  121. <el-image :src="scope.row.pic"></el-image>
  122. </template>
  123. </el-table-column>
  124. <el-table-column
  125. label="频道简介"
  126. prop="description"
  127. align="center"
  128. show-overflow-tooltip
  129. />
  130. <el-table-column label="操作" align="center">
  131. <template slot-scope="scope">
  132. <el-button type="text" @click="edit(scope, true)"
  133. >查看</el-button
  134. >
  135. <el-button type="text" @click="edit(scope)" :disabled="disabled"
  136. >编辑</el-button
  137. >
  138. <el-button
  139. v-if="scope.row.sort > 3"
  140. type="text"
  141. icon="el-icon-caret-top"
  142. @click="getChange(scope.row.id, scope.row.sort - 1)"
  143. :disabled="disabled"
  144. />
  145. <el-button
  146. v-if="scope.row.sort > 2 && scope.row.sort < 12"
  147. type="text"
  148. icon="el-icon-caret-bottom"
  149. @click="getChange(scope.row.id, scope.row.sort + 1)"
  150. :disabled="disabled"
  151. />
  152. </template>
  153. </el-table-column>
  154. </el-table>
  155. </el-form-item>
  156. </el-form>
  157. <div slot="footer" v-if="index !== 1">
  158. <el-button @click="cancel">取消</el-button>
  159. <el-button type="primary" @click="getSubmit">确定</el-button>
  160. </div>
  161. </el-dialog>
  162. </div>
  163. </template>
  164. <script>
  165. import {
  166. change,
  167. channelPage,
  168. create,
  169. devList,
  170. editPage,
  171. getRemove,
  172. page,
  173. } from "@/api/operation/channel";
  174. import { dialogCallBack } from "@/utils/DialogUtil";
  175. export default {
  176. name: "OperationChannel",
  177. data() {
  178. return {
  179. // 遮罩层
  180. loading: false,
  181. dialog_loading: false,
  182. // 列表
  183. tableData: [],
  184. list: [],
  185. // 弹窗
  186. dialogVisible: false,
  187. title: "",
  188. // 设备
  189. devOptions: [],
  190. allDevOptions: [],
  191. // 表单
  192. form: {
  193. pageNum: 1,
  194. pageSize: 10,
  195. },
  196. index: 0,
  197. dialogForm: {},
  198. ids: [],
  199. // 频道规则Id
  200. obj: {},
  201. // 部署形式
  202. typeOptions: [
  203. {
  204. value: 0,
  205. label: "注册用户-默认",
  206. },
  207. {
  208. value: 1,
  209. label: "绑定特定设备",
  210. },
  211. ],
  212. // 只读
  213. disabled: false,
  214. };
  215. },
  216. watch: {
  217. ids(val) {
  218. this.dialogForm.deviceIds = val.join(",");
  219. },
  220. },
  221. mounted() {
  222. this.getDevList();
  223. this.getList();
  224. },
  225. methods: {
  226. // 列表
  227. getList() {
  228. this.loading = true;
  229. page(this.form).then((res) => {
  230. if (res.code === 0) {
  231. this.tableData = res.data;
  232. this.loading = false;
  233. }
  234. });
  235. },
  236. // 全部设备
  237. getDevList() {
  238. devList(1).then((res) => {
  239. if (res.code === 0) {
  240. this.allDevOptions = [];
  241. res.data.map((i) => {
  242. this.allDevOptions.push({
  243. value: i.clientTypeId,
  244. label: i.name,
  245. });
  246. });
  247. }
  248. });
  249. },
  250. // 编辑
  251. edit(e, boolean) {
  252. this.dialogVisible = false;
  253. this.$router.push({
  254. path: `/operation/channel/detail`,
  255. query: {
  256. channelId: e.row.id,
  257. audioType: e.row.channelType,
  258. index: e.$index,
  259. boolean: boolean,
  260. },
  261. });
  262. },
  263. // 删除
  264. getDelete(row) {
  265. var that = this;
  266. dialogCallBack(that, function () {
  267. that
  268. .$confirm(`是否删除${row.name}?`, "提示:", {
  269. type: "warning",
  270. })
  271. .then(() => {
  272. getRemove(row.id).then((res) => {
  273. if (res.code === 0) {
  274. that.$message.success("删除成功!");
  275. that.getList();
  276. }
  277. });
  278. });
  279. });
  280. },
  281. // 弹窗
  282. getDialog(title, row, index, boolean) {
  283. this.dialogVisible = true;
  284. this.title = title;
  285. this.index = index + 1;
  286. this.obj = row;
  287. this.disabled = boolean;
  288. // 新增 / 编辑时的设备
  289. devList(0).then((res) => {
  290. if (res.code === 0) {
  291. this.devOptions = res.data;
  292. if (this.title !== "新增") {
  293. this.devOptions.unshift.apply(this.devOptions, row.deviceList);
  294. }
  295. }
  296. });
  297. if (title !== "新增") {
  298. this.dialogForm = row;
  299. if (this.index !== 1) {
  300. this.ids = this.dialogForm.deviceIds.split(",");
  301. }
  302. this.getPage(row);
  303. }
  304. },
  305. // 十二频道
  306. getPage(row) {
  307. channelPage(row.id).then((res) => {
  308. if (res.code === 0) {
  309. this.list = res.data;
  310. this.dialog_loading = false;
  311. }
  312. });
  313. },
  314. // 创建
  315. getSubmit() {
  316. if (this.title === "编辑") {
  317. editPage(this.dialogForm).then((res) => {
  318. if (res.code === 0) {
  319. this.$message.success("修改成功!");
  320. this.dialogVisible = false;
  321. this.getList();
  322. }
  323. });
  324. } else {
  325. create({
  326. name: this.dialogForm.name,
  327. deviceIds: this.dialogForm.deviceIds,
  328. type: 1,
  329. }).then((res) => {
  330. if (res.code === 0) {
  331. this.$message.success("新增成功!");
  332. this.dialogVisible = false;
  333. this.getList();
  334. }
  335. });
  336. }
  337. },
  338. // 排序
  339. getChange(id, sort) {
  340. change({
  341. id: id,
  342. sort: sort,
  343. }).then((res) => {
  344. if (res.code === 0) {
  345. this.$message.success("修改成功!");
  346. this.getPage(this.obj);
  347. }
  348. });
  349. },
  350. // 取消
  351. cancel() {
  352. this.dialogVisible = false;
  353. this.ids = [];
  354. this.dialogForm = {};
  355. this.getList();
  356. },
  357. // 字典翻译
  358. typeFormatter(row) {
  359. return this.selectDictLabel(this.typeOptions, row.type);
  360. },
  361. devFormatter(row) {
  362. return row.deviceIds
  363. ? row.deviceIds
  364. .split(",")
  365. .map((i) => this.selectDictLabel(this.allDevOptions, i))
  366. .join(",")
  367. : "";
  368. },
  369. },
  370. };
  371. </script>