index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <div class="app-container syntheticMusic">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item style="float: right;">
  5. <el-col :span="1.5" v-hasPermi="['laboratory:synthesis:add']">
  6. <p class="add-button-one-90"
  7. @click="handleAdd"
  8. ><i class="el-icon-plus"></i>新增</p>
  9. </el-col>
  10. </el-form-item>
  11. </el-form>
  12. <el-table v-loading="loading" :data="synthesisList" @selection-change="handleSelectionChange">
  13. <el-table-column type="selection" width="55" align="center" />
  14. <el-table-column label="主键id" align="center" prop="id" />
  15. <el-table-column label="音乐地址" align="center" prop="musicUrl" />
  16. <el-table-column label="音量大小" align="center" prop="musicVolume" />
  17. <el-table-column label="背景音乐地址" align="center" prop="bgmusicUrl" />
  18. <el-table-column label="背景音乐大小" align="center" prop="bgmusicVolume" />
  19. <el-table-column label="合成音乐新地址" align="center" prop="newMusicUrl" />
  20. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160" v-if="tableButtonType">
  21. <template slot-scope="scope">
  22. <div class="button-box">
  23. <p class="table-min-button"
  24. style="margin-right:10px;"
  25. @click="handleUpdate(scope.row)"
  26. v-hasPermiAnd="['laboratory:synthesis:query','laboratory:synthesis:edit']"
  27. >修改</p>
  28. <p class="table-min-button"
  29. @click="handleDelete(scope.row)"
  30. v-hasPermi="['laboratory:synthesis:remove']"
  31. >删除</p>
  32. </div>
  33. </template>
  34. </el-table-column>
  35. </el-table>
  36. <pagination :page-sizes="[20, 30, 40, 50]"
  37. v-show="total>0"
  38. :total="total"
  39. :page.sync="queryParams.pageNum"
  40. :limit.sync="queryParams.pageSize"
  41. @pagination="getList"
  42. />
  43. <!-- 添加或修改音乐合成对话框 -->
  44. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  45. <el-form ref="form" :model="form" :rules="rules" label-width="110px">
  46. <el-form-item label="预案" prop="riskPlanId">
  47. <el-select v-model="form.riskPlanId" placeholder="请选择预案" clearable style="width:350px;">
  48. <el-option
  49. v-for="dict in riskPlanList"
  50. :key="dict.id"
  51. :label="dict.name"
  52. :value="dict.id"
  53. ></el-option>
  54. </el-select>
  55. </el-form-item>
  56. <el-form-item label="音乐地址" prop="musicUrl">
  57. <el-input v-model="form.musicUrl" placeholder="请上传音乐" disabled>
  58. <template slot="append">
  59. <el-upload
  60. :action="uploadImgUrl"
  61. :show-file-list="false"
  62. accept="audio/mpeg"
  63. :on-success="(res, file)=>handleAvatarSuccess(res, file,1)"
  64. :headers="headers"
  65. :before-upload="beforeAvatarUpload">
  66. <p style="margin:0;">上传</p>
  67. </el-upload>
  68. </template>
  69. </el-input>
  70. </el-form-item>
  71. <el-form-item label="音量大小" prop="musicVolume">
  72. <el-slider :min="0.1" :max="1" v-model="form.musicVolume" :step="0.1"></el-slider>
  73. </el-form-item>
  74. <el-form-item label="背景音乐地址" prop="bgmusicUrl">
  75. <el-input v-model="form.bgmusicUrl" placeholder="请上传背景音乐" disabled>
  76. <template slot="append">
  77. <el-upload
  78. :action="uploadImgUrl"
  79. :show-file-list="false"
  80. accept="audio/mpeg"
  81. :on-success="(res, file)=>handleAvatarSuccess(res, file,2)"
  82. :headers="headers"
  83. :before-upload="beforeAvatarUpload">
  84. <p style="margin:0;">上传</p>
  85. </el-upload>
  86. </template>
  87. </el-input>
  88. </el-form-item>
  89. <el-form-item label="背景音乐大小" prop="bgmusicVolume">
  90. <el-slider :min="0.1" :max="1" v-model="form.bgmusicVolume" :step="0.1"></el-slider>
  91. </el-form-item>
  92. </el-form>
  93. <div slot="footer" class="dialog-footer">
  94. <el-button type="primary" @click="submitForm">确 定</el-button>
  95. <el-button @click="cancel">取 消</el-button>
  96. </div>
  97. </el-dialog>
  98. </div>
  99. </template>
  100. <script>
  101. import { listSynthesis, getSynthesis, delSynthesis, addSynthesis, updateSynthesis ,listRiskPlan } from "@/api/laboratory/synthesis";
  102. import { getToken } from "@/utils/auth";
  103. export default {
  104. name: "Synthesis",
  105. data() {
  106. return {
  107. tableButtonType:this.hasPermiDom(['exam:el_classify:query','exam:el_classify:edit','exam:el_classify:remove']),
  108. uploadImgUrl: window.location.href.split('://')[0]+'://' + process.env.VUE_APP_BASE_API + "/file/upload", // 上传的图片服务器地址
  109. headers: {
  110. Authorization: "Bearer " + getToken(),
  111. },
  112. // 遮罩层
  113. loading: true,
  114. // 选中数组
  115. ids: [],
  116. // 非单个禁用
  117. single: true,
  118. // 非多个禁用
  119. multiple: true,
  120. // 显示搜索条件
  121. showSearch: true,
  122. // 总条数
  123. total: 0,
  124. // 音乐合成表格数据
  125. synthesisList: [],
  126. riskPlanList: [],
  127. // 弹出层标题
  128. title: "",
  129. // 是否显示弹出层
  130. open: false,
  131. // 查询参数
  132. queryParams: {
  133. pageNum: 1,
  134. pageSize:20,
  135. musicUrl: null,
  136. musicVolume: null,
  137. bgmusicUrl: null,
  138. bgmusicVolume: null,
  139. newMusicUrl: null,
  140. },
  141. // 表单参数
  142. form: {
  143. musicUrl:"",
  144. musicVolume:5,
  145. bgmusicUrl:"",
  146. bgmusicVolume:5,
  147. },
  148. // 表单校验
  149. rules: {
  150. riskPlanId: [
  151. { required: true, message: "请选择预案", trigger: "blur" },
  152. ],
  153. musicUrl: [
  154. { required: true, message: "请上传音乐", trigger: "blur" },
  155. ],
  156. bgmusicUrl: [
  157. { required: true, message: "请上传背景音乐", trigger: "blur" },
  158. ],
  159. }
  160. };
  161. },
  162. created() {
  163. this.getList();
  164. this.getRiskPlanList();
  165. },
  166. methods: {
  167. /** 查询预案列表 */
  168. getRiskPlanList()
  169. {
  170. listRiskPlan().then(response => {
  171. // this.deptOptions = response.data;
  172. this.$set(this, 'riskPlanList', response.data)
  173. });
  174. },
  175. //上传
  176. handleAvatarSuccess(res, file, type) {
  177. // console.log("res",res);
  178. // console.log("file",file);
  179. // console.log("type",type);
  180. if(type == 1){
  181. this.$set(this.form,'musicUrl',res.data.url);
  182. }else if(type == 2){
  183. this.$set(this.form,'bgmusicUrl',res.data.url);
  184. }
  185. },
  186. beforeAvatarUpload(file) {
  187. let type = false;
  188. console.log('file',file);
  189. if (file.type == 'audio/mpeg') {
  190. type = true;
  191. }else{
  192. this.$message.error('只能上传mp3格式');
  193. type = false;
  194. }
  195. return type;
  196. },
  197. /** 查询音乐合成列表 */
  198. getList() {
  199. this.loading = true;
  200. listSynthesis(this.queryParams).then( response => {
  201. this.synthesisList = response.rows;
  202. this.total = response.total;
  203. this.loading = false;
  204. });
  205. },
  206. // 取消按钮
  207. cancel() {
  208. this.open = false;
  209. this.reset();
  210. },
  211. // 表单重置
  212. reset() {
  213. this.form = {
  214. musicUrl:"",
  215. musicVolume:0.5,
  216. bgmusicUrl:"",
  217. bgmusicVolume:0.5,
  218. };
  219. this.resetForm("form");
  220. },
  221. /** 搜索按钮操作 */
  222. handleQuery() {
  223. this.queryParams.pageNum = 1;
  224. this.getList();
  225. },
  226. /** 重置按钮操作 */
  227. resetQuery() {
  228. this.resetForm("queryForm");
  229. this.handleQuery();
  230. },
  231. // 多选框选中数据
  232. handleSelectionChange(selection) {
  233. this.ids = selection.map(item => item.id)
  234. this.single = selection.length!==1
  235. this.multiple = !selection.length
  236. },
  237. /** 新增按钮操作 */
  238. handleAdd() {
  239. this.reset();
  240. this.open = true;
  241. this.title = "添加音乐合成";
  242. },
  243. /** 修改按钮操作 */
  244. handleUpdate(row) {
  245. this.reset();
  246. const id = row.id || this.ids
  247. getSynthesis(id).then( response => {
  248. this.form = response.data;
  249. this.open = true;
  250. this.title = "修改音乐合成";
  251. });
  252. },
  253. /** 提交按钮 */
  254. submitForm() {
  255. this.$refs["form"].validate(valid => {
  256. if (valid) {
  257. if (this.form.id != null) {
  258. updateSynthesis(this.form).then( response => {
  259. this.msgSuccess("修改成功");
  260. this.open = false;
  261. this.getList();
  262. });
  263. } else {
  264. addSynthesis(this.form).then( response => {
  265. this.msgSuccess("新增成功");
  266. this.open = false;
  267. this.getList();
  268. });
  269. }
  270. }
  271. });
  272. },
  273. /** 删除按钮操作 */
  274. handleDelete(row) {
  275. const ids = row.id || this.ids;
  276. this.$confirm('是否确认删除音乐合成编号为"' + ids + '"的数据项?', "警告", {
  277. confirmButtonText: "确定",
  278. cancelButtonText: "取消",
  279. type: "warning"
  280. }).then(function() {
  281. return delSynthesis(ids);
  282. }).then(() => {
  283. this.getList();
  284. this.msgSuccess("删除成功");
  285. }).catch(() => {});
  286. },
  287. /** 导出按钮操作 */
  288. handleExport() {
  289. this.download('laboratory/synthesis/export', {
  290. ...this.queryParams
  291. }, `laboratory_synthesis.xlsx`)
  292. }
  293. }
  294. };
  295. </script>
  296. <style scoped lang="scss">
  297. .syntheticMusic{
  298. padding:20px!important;
  299. overflow: hidden;
  300. display: flex;
  301. flex-direction: column;
  302. .button-box{
  303. margin:0 auto;
  304. width:190px;
  305. display: flex;
  306. }
  307. }
  308. </style>