index.vue 11 KB

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