index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <div class="scene">
  3. <MainTop :crumb="[{ name: '场景管理' }]" />
  4. <div class="table-interface">
  5. <div class="top-body">
  6. <div class="info-top">
  7. <el-form
  8. :model="ruleForm"
  9. :rules="rules"
  10. ref="ruleForm"
  11. label-width="0px"
  12. class="demo-ruleForm"
  13. >
  14. <el-form-item label="" prop="name">
  15. <el-input
  16. v-model="ruleForm.name"
  17. placeholder="请输入场景名称搜索"
  18. style="width: 220px; margin-right: 10px;"
  19. ></el-input>
  20. <el-button type="primary" @click="find"
  21. >查找</el-button
  22. >
  23. <el-button @click="reset">重置</el-button>
  24. <el-button style="float: right;" type="primary" @click="$router.push('/scene/addScene')"
  25. >新增场景</el-button
  26. >
  27. </el-form-item>
  28. </el-form>
  29. </div>
  30. <div class="conten">
  31. <div class="box" v-for="item in list" :key="item.id">
  32. <a :href="item.urlScene">
  33. <img :src="'https://project.4dage.com/8002/'+item.thumb" alt="">
  34. </a>
  35. <div class="txt">
  36. <p>{{item.name}}</p>
  37. <div>
  38. <span @click="$router.push(`/scene/editScene/${item.id}`)">编辑&nbsp;</span>
  39. <span @click="remove(item.id)">&nbsp;删除</span>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. </template>
  48. <script>
  49. import MainTop from '@/components/main-top'
  50. export default {
  51. name: 'Scene',
  52. components: {
  53. MainTop
  54. },
  55. data () {
  56. // 这里存放数据
  57. return {
  58. ruleForm: {
  59. name: ''
  60. },
  61. rules: {
  62. name: [
  63. ]
  64. },
  65. list: []
  66. }
  67. },
  68. // 监听属性 类似于data概念
  69. computed: {},
  70. // 监控data中的数据变化
  71. watch: {},
  72. // 方法集合
  73. methods: {
  74. // 获取场景列表接口
  75. async getList () {
  76. let result = await this.$http({
  77. method: 'post',
  78. url: '/scene/list'
  79. })
  80. this.list = result.data
  81. },
  82. // 场景详情接口
  83. // async getDetails () {
  84. // let result = await this.$http({
  85. // method: 'post',
  86. // url: '/scene/detail/4'
  87. // })
  88. // console.log(9999999999, result)
  89. // },
  90. // 点击重置
  91. reset () {
  92. this.getList()
  93. this.ruleForm.name = ''
  94. },
  95. // 点击删除
  96. remove (id) {
  97. this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
  98. confirmButtonText: '确定',
  99. cancelButtonText: '取消',
  100. type: 'warning'
  101. }).then(() => {
  102. this.$http.get(`/scene/remove/${id}`).then(res => {
  103. if (res.code === 0) {
  104. this.$notify.success({
  105. title: '提示',
  106. message: '删除成功',
  107. duration: 2000
  108. })
  109. this.getList()
  110. } else {
  111. this.$notify.error({
  112. title: '错误',
  113. message: res.msg,
  114. duration: 2000
  115. })
  116. }
  117. })
  118. }).catch(() => {
  119. this.$message({
  120. type: 'info',
  121. message: '已取消删除'
  122. })
  123. })
  124. },
  125. // 点击查找
  126. find () {
  127. if (!this.ruleForm.name) return this.$message.warning('不能为空')
  128. // console.log(this.list)
  129. this.list = this.list.filter(v => {
  130. return v.name.includes(this.ruleForm.name)
  131. })
  132. }
  133. },
  134. // 生命周期 - 创建完成(可以访问当前this实例)
  135. created () {},
  136. // 生命周期 - 挂载完成(可以访问DOM元素)
  137. mounted () {
  138. this.getList()
  139. },
  140. beforeCreate () {}, // 生命周期 - 创建之前
  141. beforeMount () {}, // 生命周期 - 挂载之前
  142. beforeUpdate () {}, // 生命周期 - 更新之前
  143. updated () {}, // 生命周期 - 更新之后
  144. beforeDestroy () {}, // 生命周期 - 销毁之前
  145. destroyed () {}, // 生命周期 - 销毁完成
  146. activated () {} // 如果页面有keep-alive缓存功能,这个函数会触发
  147. }
  148. </script>
  149. <style scoped>
  150. .table-interfac {
  151. overflow-y: auto;
  152. overflow-x: hidden;
  153. height: calc(100% - 3rem);
  154. }
  155. .top-body {
  156. margin: 1rem 0;
  157. }
  158. .info-top {
  159. padding: 20px 70px 20px 36px;
  160. width: 100%;
  161. border-bottom: 1px #a5a5a5 solid;
  162. }
  163. .conten {
  164. display: flex;
  165. flex-wrap: wrap;
  166. width: 100%;
  167. min-height: 376px;
  168. padding: 25px;
  169. }
  170. .box {
  171. cursor: pointer;
  172. width: 20%;
  173. height: 205px;
  174. }
  175. .box img {
  176. width: 90%;
  177. max-height: 150px;
  178. }
  179. .txt {
  180. margin-top: 18px;
  181. display: flex;
  182. justify-content: space-between;
  183. }
  184. .txt>div {
  185. padding-right: 30px;
  186. }
  187. </style>