index.vue 11 KB

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