index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <!-- 音频管理 资源平台 -->
  2. <template>
  3. <div class="app-container">
  4. <el-button
  5. type="primary"
  6. icon="el-icon-plus"
  7. size="mini"
  8. @click="getDialog()"
  9. v-hasPermi="['music:platform:add']"
  10. >新增</el-button
  11. >
  12. <!-- 列表 -->
  13. <el-table :data="tableData" v-loading="loading">
  14. <el-table-column type="index" label="序号" align="center" />
  15. <el-table-column label="资源平台" prop="name" align="center" />
  16. <el-table-column
  17. label="音频类型"
  18. prop="audioType"
  19. align="center"
  20. :formatter="audioFormatter"
  21. />
  22. <el-table-column
  23. label="对接方式"
  24. prop="joinType"
  25. align="center"
  26. :formatter="joinTypeFormatter"
  27. />
  28. <el-table-column label="操作" align="center">
  29. <template slot-scope="scope">
  30. <el-button
  31. type="text"
  32. @click="getDialog(scope.row.id)"
  33. v-hasPermi="['music:platform:edit']"
  34. >编辑
  35. </el-button>
  36. <el-button
  37. type="delete"
  38. @click="getDelete(scope.row)"
  39. v-hasPermi="['music:platform:delete']"
  40. >删除
  41. </el-button>
  42. </template>
  43. </el-table-column>
  44. </el-table>
  45. <pagination
  46. v-show="total > 0"
  47. :total="total"
  48. :page.sync="form.pageNum"
  49. :limit.sync="form.pageSize"
  50. @pagination="getList"
  51. />
  52. <!-- 弹窗 -->
  53. <el-dialog
  54. :visible.sync="dialogVisible"
  55. :title="title"
  56. width="500px"
  57. :before-close="cancel"
  58. >
  59. <el-form
  60. :model="dialogForm"
  61. :rules="rules"
  62. ref="dialogForm"
  63. label-width="100px"
  64. >
  65. <el-form-item label="资源平台:" prop="name">
  66. <el-input
  67. v-model="dialogForm.name"
  68. placeholder="请输入资源平台名称"
  69. />
  70. </el-form-item>
  71. <el-form-item label="音频类型:" prop="audioType">
  72. <el-select
  73. v-model="dialogForm.audioType"
  74. multiple
  75. placeholder="请选择音频类型"
  76. >
  77. <el-option
  78. v-for="item in audioOptions"
  79. :key="item.value"
  80. :value="item.value.toString()"
  81. :label="item.label"
  82. />
  83. </el-select>
  84. </el-form-item>
  85. <el-form-item label="对接方式:" prop="joinType">
  86. <el-select
  87. v-model="dialogForm.joinType"
  88. multiple
  89. placeholder="请选择资源对接方式"
  90. >
  91. <el-option
  92. v-for="item in joinTypeOptions"
  93. :key="item.value"
  94. :value="item.value.toString()"
  95. :label="item.label"
  96. :disabled="item.disabled"
  97. />
  98. </el-select>
  99. </el-form-item>
  100. <el-form-item style="text-align: right">
  101. <el-button @click="cancel">取消</el-button>
  102. <el-button type="primary" @click="getSubmit">确定</el-button>
  103. </el-form-item>
  104. </el-form>
  105. </el-dialog>
  106. </div>
  107. </template>
  108. <script>
  109. import { detail, list, remove, submit } from "@/api/music/platform";
  110. import { audioMixin } from "@/mixin/index";
  111. import { dialogCallBack } from "@/utils/DialogUtil";
  112. export default {
  113. name:"MusicPlatform",
  114. mixins: [audioMixin],
  115. data() {
  116. return {
  117. // 遮罩层
  118. loading: false,
  119. // 列表表单
  120. form: {
  121. pageNum: 1,
  122. pageSize: 10,
  123. },
  124. // 总数
  125. total: 0,
  126. // 列表
  127. tableData: [],
  128. // 弹窗
  129. dialogVisible: false,
  130. title: "",
  131. // 提交表单
  132. dialogForm: {
  133. name: "",
  134. audioType: [],
  135. joinType: [],
  136. },
  137. // 校验
  138. rules: {
  139. name: [
  140. {
  141. required: true,
  142. message: "请输入资源平台名称",
  143. trigger: "blur",
  144. },
  145. {
  146. max: 20,
  147. message: "名称不得超过20个字符",
  148. trigger: "blur",
  149. },
  150. ],
  151. audioType: [
  152. {
  153. required: true,
  154. message: "请选择音频类型",
  155. trigger: "change",
  156. },
  157. ],
  158. joinType: [
  159. {
  160. required: true,
  161. message: "请选择资源对接方式",
  162. trigger: "change",
  163. },
  164. ],
  165. },
  166. // 对接方式
  167. joinTypeOptions: [
  168. {
  169. value: 1,
  170. label: "API接口",
  171. },
  172. {
  173. value: 2,
  174. label: "本地管理",
  175. },
  176. {
  177. value: 3,
  178. label: "小程序",
  179. },
  180. ],
  181. };
  182. },
  183. watch: {
  184. "dialogForm.joinType"(val) {
  185. if (val) {
  186. this.joinTypeOptions[1].disabled =
  187. val.findIndex((i) => i === "1") !== -1 ? true : false;
  188. this.joinTypeOptions[0].disabled =
  189. val.findIndex((i) => i === "2") !== -1 ? true : false;
  190. }
  191. },
  192. },
  193. mounted() {
  194. this.getList();
  195. },
  196. methods: {
  197. // 列表
  198. getList() {
  199. this.loading = true;
  200. list(this.form).then((res) => {
  201. if (res.code === 0) {
  202. this.tableData = res.data.records;
  203. this.total = res.data.total;
  204. this.loading = false;
  205. }
  206. });
  207. },
  208. // 弹窗
  209. getDialog(id) {
  210. this.dialogVisible = true;
  211. this.title = id ? "编辑" : "新增";
  212. if (id) {
  213. detail(id).then((res) => {
  214. if (res.code === 0) {
  215. this.dialogForm = res.data;
  216. this.dialogForm.audioType = res.data.audioType.split(",");
  217. this.dialogForm.joinType = res.data.joinType.split(",");
  218. }
  219. });
  220. }
  221. },
  222. // 取消
  223. cancel() {
  224. this.dialogVisible = false;
  225. this.dialogForm = {};
  226. this.$refs.dialogForm.resetFields();
  227. },
  228. // 确定
  229. getSubmit() {
  230. this.$refs.dialogForm.validate((valid) => {
  231. if (valid) {
  232. this.dialogForm.audioType = this.dialogForm.audioType.join(",");
  233. this.dialogForm.joinType = this.dialogForm.joinType.join(",");
  234. submit(this.dialogForm)
  235. .then((res) => {
  236. if (res.code === 0) {
  237. this.$message.success(`${this.title}成功!`);
  238. this.dialogVisible = false;
  239. this.getList();
  240. }
  241. })
  242. .catch(() => {
  243. this.dialogForm.id
  244. ? (this.dialogVisible = false)
  245. : this.$refs.dialogForm.resetFields();
  246. });
  247. } else {
  248. return false;
  249. }
  250. });
  251. },
  252. // 删除
  253. getDelete(row) {
  254. var that = this;
  255. dialogCallBack(that, function () {
  256. that
  257. .$confirm(`是否删除${row.name}?`, "提示:", {
  258. type: "warning",
  259. })
  260. .then(() => {
  261. remove(row.id).then((res) => {
  262. if (res.code === 0) {
  263. that.$message.success("删除成功");
  264. that.getList();
  265. }
  266. });
  267. })
  268. .catch(() => {});
  269. });
  270. },
  271. // 字典翻译
  272. audioFormatter(row) {
  273. return row.audioType
  274. ? row.audioType
  275. .split(",")
  276. .map((i) => this.selectDictLabel(this.audioOptions, i))
  277. .join(",")
  278. : "/";
  279. },
  280. joinTypeFormatter(row) {
  281. return row.joinType
  282. ? row.joinType
  283. .split(",")
  284. .map((i) => this.selectDictLabel(this.joinTypeOptions, i))
  285. .join(",")
  286. : "/";
  287. },
  288. },
  289. };
  290. </script>