index.vue 6.7 KB

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