index.vue 4.6 KB

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