index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <div class='app-container'>
  3. <div class="left">
  4. <el-button type="primary" plain icon="Plus" @click="getDialog()"
  5. v-hasPermi="['scene:presets:addScene']">新增场景</el-button>
  6. <el-input class="search" v-model="data.form.takeName" placeholder="搜索场景名称" clearable>
  7. <template #append>
  8. <el-button icon="Search" @click="getSearch" />
  9. </template>
  10. </el-input>
  11. <draggable class="contentList" v-model="data.tableData" item-key="id" chosenClass="chosenClass" data-id="content"
  12. :group="{ name: 'componentGroup', pull: 'clone', put: false }" :sort="false" filter=".auditStatus" @end="onEnd"
  13. forceFallback v-loading="loading">
  14. <template #item="{ element, index }">
  15. <div :class="['item', element.auditStatus === 0 ? 'auditStatus' : '']" @click="getDialog(element)">
  16. <el-icon v-if="element.auditStatus === 2" class="close" size="18" @click.stop="getDelete(element)"
  17. v-hasPermi="['scene:presets:deleteScene']">
  18. <CircleClose />
  19. </el-icon>
  20. <img src="@/assets/icons/svg/file.svg" width="50" height="50" />
  21. <span style="margin-top: 10px">
  22. {{ element.takeName }}
  23. </span>
  24. <span v-if="element.auditStatus === 0">(待审核)</span>
  25. </div>
  26. </template>
  27. </draggable>
  28. <pagination v-show="total > 0" layout="prev, pager, next" :background="false" :total="total"
  29. v-model:page="data.form.pageNum" v-model:limit="data.form.pageSize" @pagination="getList" />
  30. </div>
  31. <div class="right">
  32. <gantt-chart path="/scene/presets/detail" type="scene" />
  33. </div>
  34. <!-- 弹窗 -->
  35. <el-dialog v-model="dialogVisible" :title="title" width="500px" :before-close="getClose">
  36. <el-form :model="data.dialogForm" ref="dialogForm" :rules="data.rules">
  37. <el-form-item label="播放音频:" prop="list">
  38. <CustomUpload v-if="title !== '编辑'" ref="customUpload" :url="`${baseUrl}/radio/tProgram/mp3/upload`" multiple
  39. showFileList @upload="upload" />
  40. <div v-else>
  41. <div v-for="item in data.dialogForm.list" :key="item.id">{{ item.name }}</div>
  42. </div>
  43. </el-form-item>
  44. <el-form-item label="场景名称:" prop="takeName">
  45. <el-input v-model="data.dialogForm.takeName" placeholder="请输入场景名称" />
  46. </el-form-item>
  47. </el-form>
  48. <template #footer>
  49. <el-button @click="getClose">取消</el-button>
  50. <el-button type="primary" @click="getSubmit">确定</el-button>
  51. </template>
  52. </el-dialog>
  53. </div>
  54. </template>
  55. <script setup>
  56. import { list, submit, detail, remove } from '@/api/scene/presets'
  57. import { checkPermi } from '@/utils/permission'
  58. import GanttChart from '@/components/GanttChart/index.vue'
  59. const baseUrl = ref(import.meta.env.VITE_APP_BASE_API)
  60. const { proxy } = getCurrentInstance();
  61. // 遮罩层
  62. const loading = ref(false)
  63. const data = reactive({
  64. // 表单
  65. form: {
  66. pageNum: 1,
  67. pageSize: 10
  68. },
  69. // 列表
  70. tableData: [],
  71. // 弹窗表单
  72. dialogForm: {},
  73. // 校验
  74. rules: {
  75. list: [{
  76. required: true, message: '请上传音频', trigger: 'change'
  77. }],
  78. takeName: [{
  79. required: true, message: '请输入场景名称', trigger: 'blur'
  80. }]
  81. }
  82. })
  83. // 总数据
  84. const total = ref(0)
  85. // 列表
  86. function getList() {
  87. loading.value = true
  88. list(data.form).then(res => {
  89. if (res.code === 0) {
  90. data.tableData = res.data.records
  91. total.value = res.data.total
  92. loading.value = false
  93. }
  94. })
  95. }
  96. getList()
  97. // 搜索
  98. function getSearch() {
  99. data.form.pageNum = 1
  100. getList()
  101. }
  102. // 拖拽前
  103. const onMove = () => {
  104. }
  105. // 拖拽结束
  106. function onEnd(params) {
  107. if (checkPermi(['scene:presets:add'])) {
  108. if (params.from.className !== params.to.className) {
  109. proxy.$modal.confirm(`是否要添加?`).then(() => {
  110. getRouter({ audioList: JSON.stringify(params.item.__draggable_context.element), disabled: true })
  111. }).catch(() => { })
  112. }
  113. } else {
  114. proxy.$modal.msgError('暂无权限')
  115. }
  116. }
  117. // 弹窗
  118. const dialogVisible = ref(false)
  119. // 弹窗标题
  120. const title = ref('')
  121. // 打开弹窗
  122. function getDialog(row) {
  123. if (row.auditStatus === 2) {
  124. if (checkPermi(['scene:presets:editScene'])) {
  125. dialogVisible.value = true
  126. title.value = '新增'
  127. if (row.takeId) {
  128. getDetail(row.takeId)
  129. }
  130. }
  131. }
  132. }
  133. // 详情
  134. function getDetail(id) {
  135. title.value = '编辑'
  136. detail({ id: id }).then(res => {
  137. if (res.code === 0) {
  138. data.dialogForm = res.data
  139. }
  140. })
  141. }
  142. // 上传音频
  143. function upload(file) {
  144. data.dialogForm.list = file
  145. }
  146. // 提交
  147. function getSubmit() {
  148. proxy.$refs.dialogForm.validate((valid) => {
  149. if (valid) {
  150. submit(data.dialogForm).then(res => {
  151. if (res.code === 0) {
  152. proxy.$modal.msgSuccess('提交成功!')
  153. getClose()
  154. getList()
  155. }
  156. })
  157. } else {
  158. return false
  159. }
  160. })
  161. }
  162. // 取消
  163. function getClose() {
  164. dialogVisible.value = false
  165. data.dialogForm = {}
  166. proxy.$refs.dialogForm.resetFields()
  167. if (title.value === '新增') {
  168. proxy.$refs.customUpload.onRefresh()
  169. }
  170. }
  171. // 删除
  172. function getDelete(row) {
  173. proxy.$modal.confirm(`是否删除${row.takeName}`).then(() => {
  174. remove(row.takeId).then(res => {
  175. if (res.code === 0) {
  176. proxy.$modal.msgSuccess('删除成功!')
  177. getList()
  178. }
  179. })
  180. }).catch(() => { })
  181. }
  182. // 新增预设
  183. function getRouter(query) {
  184. proxy.$router.push({
  185. path: `/scene/presets/detail`,
  186. query
  187. })
  188. }
  189. </script>
  190. <style lang="scss" scoped>
  191. .app-container {
  192. display: flex;
  193. }
  194. .left {
  195. min-width: 400px;
  196. position: relative;
  197. .search {
  198. margin: 15px 0;
  199. }
  200. .contentList {
  201. display: flex;
  202. flex-wrap: wrap;
  203. .item {
  204. width: 33.333333%;
  205. display: flex;
  206. flex-direction: column;
  207. font-size: 12px;
  208. align-items: center;
  209. padding: 20px 0;
  210. position: relative;
  211. .close {
  212. position: absolute;
  213. right: 35px;
  214. top: 15px;
  215. opacity: 0;
  216. }
  217. span {
  218. width: 80%;
  219. text-align: center;
  220. overflow: hidden;
  221. white-space: nowrap;
  222. text-overflow: ellipsis;
  223. }
  224. }
  225. .item:hover .close {
  226. opacity: 1;
  227. transition: all 1s;
  228. }
  229. }
  230. }
  231. .right {
  232. display: flex;
  233. flex-direction: column;
  234. min-width: 700px;
  235. width: calc(100% - 400px);
  236. height: 792px;
  237. }
  238. draggable,
  239. .label {
  240. user-select: none;
  241. }
  242. .chosenClass {
  243. display: none;
  244. background: none !important;
  245. }
  246. </style>