index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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. <div v-if="editData.currentEditIndex !== scope.$index">
  34. <span style="margin-right: 8px">
  35. {{ scope.row.indexNum }}
  36. <!-- {{ scope.$index + 1 }} -->
  37. <!-- {{ scope.row.sort || "" }} -->
  38. </span>
  39. <svg-icon
  40. icon-class="edit"
  41. @click.native="handleEditClick(scope.row, scope.$index)"
  42. />
  43. </div>
  44. <el-input
  45. v-else
  46. v-model="scope.row.indexNum"
  47. size="mini"
  48. style="width: 60px"
  49. type="number"
  50. @blur="onNumberBlur(scope.row, scope.$index)"
  51. @keyup.enter.native="onNumberBlurEnter(scope.row, scope.$index)"
  52. placeholder="序号"
  53. ref="numberInput"
  54. />
  55. </template>
  56. </el-table-column> -->
  57. <el-table-column label="操作" align="center">
  58. <template slot-scope="scope">
  59. <el-button
  60. type="text"
  61. @click="getDialog('查看', scope.row, scope.$index, true)"
  62. >查看</el-button
  63. >
  64. <el-button
  65. type="text"
  66. @click="getDialog('编辑', scope.row, scope.$index)"
  67. v-hasPermi="['operation:channel:edit']"
  68. >编辑</el-button
  69. >
  70. <el-button
  71. v-if="scope.$index !== 0"
  72. type="delete"
  73. @click="getDelete(scope.row)"
  74. v-hasPermi="['operation:channel:delete']"
  75. >
  76. 删除
  77. </el-button>
  78. </template>
  79. </el-table-column>
  80. </el-table>
  81. <!-- 弹窗 -->
  82. <el-dialog
  83. :visible.sync="dialogVisible"
  84. :title="title"
  85. width="950px"
  86. :before-close="cancel"
  87. >
  88. <el-form label-width="auto">
  89. <el-form-item
  90. v-if="index !== 1"
  91. label="频道配置名称:"
  92. style="width: 300px"
  93. >
  94. <el-input
  95. v-model="dialogForm.name"
  96. placeholder="请输入规则名称"
  97. :disabled="disabled"
  98. />
  99. </el-form-item>
  100. <el-form-item v-if="index !== 1" label="关联设备:">
  101. <el-select
  102. v-model="ids"
  103. filterable
  104. multiple
  105. placeholder="请选择关联设备"
  106. :disabled="disabled"
  107. >
  108. <el-option
  109. v-for="item in devOptions"
  110. :key="item.clientTypeId"
  111. :value="item.clientTypeId.toString()"
  112. :label="item.name"
  113. />
  114. </el-select>
  115. </el-form-item>
  116. <el-form-item
  117. v-if="title !== '新增'"
  118. label="内容列表:"
  119. style="height: 500px; overflow-y: auto"
  120. >
  121. <el-table
  122. :data="list"
  123. v-loading="dialog_loading"
  124. lazy
  125. :default-sort="{ prop: 'sort' }"
  126. >
  127. <el-table-column
  128. label="序号"
  129. prop="sort"
  130. align="center"
  131. width="100px"
  132. />
  133. <el-table-column
  134. label="频道数"
  135. prop="channelId"
  136. align="center"
  137. width="100px"
  138. />
  139. <el-table-column
  140. label="频道名称"
  141. prop="aliasName"
  142. align="center"
  143. show-overflow-tooltip
  144. />
  145. <el-table-column label="频道封面" align="center" width="100px">
  146. <template slot-scope="scope">
  147. <el-image :src="scope.row.pic"></el-image>
  148. </template>
  149. </el-table-column>
  150. <el-table-column
  151. label="频道简介"
  152. prop="description"
  153. align="center"
  154. show-overflow-tooltip
  155. />
  156. <el-table-column label="操作" align="center">
  157. <template slot-scope="scope">
  158. <el-button type="text" @click="edit(scope, true)"
  159. >查看</el-button
  160. >
  161. <el-button type="text" @click="edit(scope)" :disabled="disabled"
  162. >编辑</el-button
  163. >
  164. <el-button
  165. v-if="scope.row.sort > 3"
  166. type="text"
  167. icon="el-icon-caret-top"
  168. @click="getChange(scope.row.id, scope.row.sort - 1)"
  169. :disabled="disabled"
  170. />
  171. <el-button
  172. v-if="scope.row.sort > 2 && scope.row.sort < 12"
  173. type="text"
  174. icon="el-icon-caret-bottom"
  175. @click="getChange(scope.row.id, scope.row.sort + 1)"
  176. :disabled="disabled"
  177. />
  178. </template>
  179. </el-table-column>
  180. </el-table>
  181. </el-form-item>
  182. </el-form>
  183. <div slot="footer" v-if="index !== 1">
  184. <el-button @click="cancel">取消</el-button>
  185. <el-button type="primary" @click="getSubmit">确定</el-button>
  186. </div>
  187. </el-dialog>
  188. </div>
  189. </template>
  190. <script>
  191. import {
  192. change,
  193. channelPage,
  194. create,
  195. devList,
  196. editPage,
  197. getRemove,
  198. page,
  199. } from "@/api/operation/channel";
  200. import { dialogCallBack } from "@/utils/DialogUtil";
  201. export default {
  202. name: "OperationChannel",
  203. data() {
  204. return {
  205. editData: {
  206. currentEditIndex: -1,
  207. currentEditSort: 1,
  208. },
  209. // 遮罩层
  210. loading: false,
  211. dialog_loading: false,
  212. // 列表
  213. tableData: [],
  214. list: [],
  215. // 弹窗
  216. dialogVisible: false,
  217. title: "",
  218. // 设备
  219. devOptions: [],
  220. allDevOptions: [],
  221. // 表单
  222. form: {
  223. pageNum: 1,
  224. pageSize: 10,
  225. },
  226. index: 0,
  227. dialogForm: {},
  228. ids: [],
  229. // 频道规则Id
  230. obj: {},
  231. // 部署形式
  232. typeOptions: [
  233. {
  234. value: 0,
  235. label: "注册用户-默认",
  236. },
  237. {
  238. value: 1,
  239. label: "绑定特定设备",
  240. },
  241. ],
  242. // 只读
  243. disabled: false,
  244. };
  245. },
  246. watch: {
  247. ids(val) {
  248. this.dialogForm.deviceIds = val.join(",");
  249. },
  250. },
  251. mounted() {
  252. this.getDevList();
  253. this.getList();
  254. },
  255. methods: {
  256. // 列表
  257. getList() {
  258. this.loading = true;
  259. page(this.form).then((res) => {
  260. if (res.code === 0) {
  261. var data = res.data;
  262. for (var i = 0; i < data.length; i++) {
  263. data[i].indexNum = i + 1;
  264. }
  265. this.tableData = data;
  266. this.loading = false;
  267. }
  268. });
  269. },
  270. // 全部设备
  271. getDevList() {
  272. devList(1).then((res) => {
  273. if (res.code === 0) {
  274. this.allDevOptions = [];
  275. res.data.map((i) => {
  276. this.allDevOptions.push({
  277. value: i.clientTypeId,
  278. label: i.name,
  279. });
  280. });
  281. }
  282. });
  283. },
  284. // 编辑
  285. edit(e, boolean) {
  286. this.dialogVisible = false;
  287. this.$router.push({
  288. path: `/operation/channel/detail`,
  289. query: {
  290. channelId: e.row.id,
  291. audioType: e.row.channelType,
  292. index: e.$index,
  293. boolean: boolean,
  294. },
  295. });
  296. },
  297. // 删除
  298. getDelete(row) {
  299. var that = this;
  300. dialogCallBack(that, function () {
  301. that
  302. .$confirm(`是否删除${row.name}?`, "提示:", {
  303. type: "warning",
  304. })
  305. .then(() => {
  306. getRemove(row.id).then((res) => {
  307. if (res.code === 0) {
  308. that.$message.success("删除成功!");
  309. that.getList();
  310. }
  311. });
  312. });
  313. });
  314. },
  315. // 弹窗
  316. getDialog(title, row, index, boolean) {
  317. this.dialogVisible = true;
  318. this.title = title;
  319. this.index = index + 1;
  320. this.obj = row;
  321. this.disabled = boolean;
  322. // 新增 / 编辑时的设备
  323. devList(0).then((res) => {
  324. if (res.code === 0) {
  325. this.devOptions = res.data;
  326. if (this.title !== "新增") {
  327. this.devOptions.unshift.apply(this.devOptions, row.deviceList);
  328. }
  329. }
  330. });
  331. if (title !== "新增") {
  332. this.dialogForm = row;
  333. if (this.index !== 1) {
  334. this.ids = this.dialogForm.deviceIds.split(",");
  335. }
  336. this.getPage(row);
  337. }
  338. },
  339. // 十二频道
  340. getPage(row) {
  341. channelPage(row.id).then((res) => {
  342. if (res.code === 0) {
  343. this.list = res.data;
  344. this.dialog_loading = false;
  345. }
  346. });
  347. },
  348. // 创建
  349. getSubmit() {
  350. if (this.title === "编辑") {
  351. editPage(this.dialogForm).then((res) => {
  352. if (res.code === 0) {
  353. this.$message.success("修改成功!");
  354. this.dialogVisible = false;
  355. this.getList();
  356. }
  357. });
  358. } else {
  359. create({
  360. name: this.dialogForm.name,
  361. deviceIds: this.dialogForm.deviceIds,
  362. type: 1,
  363. }).then((res) => {
  364. if (res.code === 0) {
  365. this.$message.success("新增成功!");
  366. this.dialogVisible = false;
  367. this.getList();
  368. }
  369. });
  370. }
  371. },
  372. // 点击编辑图标显示输入框
  373. handleEditClick(row, index) {
  374. this.editData.currentEditIndex = index;
  375. this.editData.currentEditSort = row.indexNum;
  376. this.$nextTick(() => {
  377. this.$refs.numberInput.focus();
  378. });
  379. },
  380. onNumberBlurEnter(row, index) {
  381. this.editData.currentEditIndex = -1;
  382. },
  383. // 输入框失去焦点时隐藏
  384. onNumberBlur(row, index) {
  385. var newSort = row.indexNum;
  386. if (newSort === "") {
  387. row.indexNum = this.editData.currentEditSort;
  388. this.$message.warning("序号不能为空");
  389. return;
  390. }
  391. if (newSort <= 0) {
  392. row.indexNum = this.editData.currentEditSort;
  393. this.$message.warning("序号必须大于0");
  394. return;
  395. }
  396. if (newSort === this.editData.currentEditSort) {
  397. this.editData.currentEditIndex = -1;
  398. return;
  399. }
  400. ///删除第index个元素
  401. this.tableData.splice(index, 1);
  402. this.tableData.splice(newSort - 1, 0, row);
  403. for (var i = 0; i < this.tableData.length; i++) {
  404. this.tableData[i].indexNum = i + 1;
  405. }
  406. this.editData.currentEditIndex = -1;
  407. // 检查序号是否重复
  408. // const isDuplicate = this.tableData.some(
  409. // (item, i) => i !== index && item.sortIndex === newSort
  410. // );
  411. // if (isDuplicate) {
  412. // this.$message.warning("序号已存在");
  413. // } else {
  414. // // 更新到tableData
  415. // this.$set(this.tableData, index, {
  416. // ...row,
  417. // sortIndex: newSort,
  418. // });
  419. // console.log(
  420. // "序号修改成功:",
  421. // newSort,
  422. // "row.sortIndex",
  423. // row.sortIndex,
  424. // "this.tableData",
  425. // this.tableData[index].sortIndex
  426. // );
  427. // 隐藏编辑框
  428. // this.editData.currentEditIndex = -1;
  429. // }
  430. },
  431. // 排序
  432. getChange(id, sort) {
  433. change({
  434. id: id,
  435. sort: sort,
  436. }).then((res) => {
  437. if (res.code === 0) {
  438. this.$message.success("修改成功!");
  439. this.getPage(this.obj);
  440. }
  441. });
  442. },
  443. // 取消
  444. cancel() {
  445. this.dialogVisible = false;
  446. this.ids = [];
  447. this.dialogForm = {};
  448. this.getList();
  449. },
  450. // 字典翻译
  451. typeFormatter(row) {
  452. return this.selectDictLabel(this.typeOptions, row.type);
  453. },
  454. devFormatter(row) {
  455. return row.deviceIds
  456. ? row.deviceIds
  457. .split(",")
  458. .map((i) => this.selectDictLabel(this.allDevOptions, i))
  459. .join(",")
  460. : "";
  461. },
  462. },
  463. };
  464. </script>