index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <div class='app-container'>
  3. <h1>猫王音响-添加电台</h1>
  4. <h1>请输入要添加的网络电台信息</h1>
  5. <div class="form" v-for="(item, index) in form" :key="index">
  6. <div>电台{{ index + 1 }}</div>
  7. <uni-icons v-show="index !== 0" class="close" type="closeempty" color="#FFF" size="18" @click="getClose(index)" />
  8. <input type="text" v-model="item.name" placeholder="请输入电台名称">
  9. <input type="text" v-model="item.url" placeholder="请输入链接地址">
  10. </div>
  11. <button v-show="form.length < 3" class="plus" @click="getAdd">+ 新增</button>
  12. <button class="submit" type="submit" circle @click="getSubmit">提交</button>
  13. <div class="list">
  14. <h2>已添加的电台</h2>
  15. <div class="item" v-for="item in list" :key="item.id">
  16. <div>{{ item.name }}</div>
  17. <div>{{ item.url }}</div>
  18. <uni-icons class="delete" type="more-filled" size="24" @click="getDelete(item)" />
  19. </div>
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. import { list, submit, remove } from "@/api/channel"
  25. export default {
  26. data() {
  27. return {
  28. // 设备信息
  29. dev: {},
  30. // 列表表单
  31. listForm: {
  32. pageNum: 1,
  33. pageSize: 10
  34. },
  35. // 列表
  36. list: [],
  37. // 更多
  38. hasMore: false,
  39. // 表单
  40. form: [{
  41. name: "",
  42. url: ""
  43. }]
  44. }
  45. },
  46. onLoad(e) {
  47. this.dev = e
  48. this.getList()
  49. },
  50. methods: {
  51. // 列表
  52. getList() {
  53. list({ ...this.dev, ...this.listForm }).then(res => {
  54. if (res.data.code === 0) {
  55. res.data.data.records.map(i => this.list.push(i))
  56. this.hasMore = res.data.data.hasMore
  57. }
  58. })
  59. },
  60. // 添加
  61. getAdd() {
  62. this.form.push({
  63. name: "",
  64. url: ""
  65. })
  66. },
  67. // 关闭
  68. getClose(index) {
  69. this.form.splice(index, 1)
  70. },
  71. // 提交
  72. getSubmit() {
  73. var rules = false
  74. this.form.map(i => {
  75. if (i.name !== "" && i.url !== "") {
  76. i.deviceMac = this.dev.deviceMac
  77. i.deviceType = this.dev.deviceType
  78. i.sign = this.dev.sign
  79. rules = true
  80. }
  81. })
  82. if (rules) {
  83. submit(this.form).then(res => {
  84. if (res.data.code === 0) {
  85. this.list = []
  86. this.getList()
  87. this.form = [{
  88. name: "",
  89. url: ""
  90. }]
  91. }
  92. })
  93. } else {
  94. uni.showToast({
  95. title: '电台信息不能为空!',
  96. icon: 'none'
  97. })
  98. }
  99. },
  100. // 删除
  101. getDelete(item) {
  102. uni.showModal({
  103. title: '提示',
  104. content: `是否删除名称为${item.name}的电台?`,
  105. confirmColor: '#78B06A',
  106. success: (e) => {
  107. if (e.confirm) {
  108. remove({
  109. id: item.id,
  110. ...this.dev
  111. }).then(res => {
  112. if (res.data.code === 0) {
  113. this.list = []
  114. this.getList(this.dev)
  115. }
  116. })
  117. }
  118. }
  119. })
  120. }
  121. },
  122. onReachBottom() {
  123. if(this.hasMore) {
  124. this.listForm.pageNum++
  125. this.getList()
  126. }
  127. }
  128. }
  129. </script>
  130. <style lang="scss" scoped>
  131. .plus {
  132. width: 160rpx;
  133. height: 70rpx;
  134. line-height: 70rpx;
  135. font-size: 28rpx;
  136. margin: 0;
  137. font-weight: bold;
  138. background: none;
  139. color: #FFF;
  140. border: 1px solid #FFF;
  141. }
  142. h1 {
  143. font-size: 16px;
  144. line-height: 50px;
  145. text-align: center;
  146. }
  147. h2 {
  148. font-size: 16px;
  149. line-height: 50px;
  150. }
  151. .list {
  152. .item {
  153. border: 1px solid #FFF;
  154. border-radius: 8px;
  155. padding: 20px;
  156. display: flex;
  157. flex-direction: column;
  158. justify-content: space-around;
  159. position: relative;
  160. margin-bottom: 15px;
  161. background-color: #FFF;
  162. color: #000;
  163. .delete {
  164. position: absolute;
  165. right: 20px;
  166. transform: rotate(90deg);
  167. }
  168. }
  169. }
  170. .form {
  171. display: flex;
  172. flex-direction: column;
  173. justify-content: center;
  174. margin: 8px 0;
  175. border: 1px solid #FFF;
  176. padding: 20px;
  177. border-radius: 8px;
  178. position: relative;
  179. uni-input {
  180. background-color: #FFF;
  181. color: #000;
  182. }
  183. .close {
  184. position: absolute;
  185. right: 10px;
  186. top: 10px;
  187. }
  188. }
  189. .submit {
  190. height: 80rpx;
  191. line-height: 80rpx;
  192. margin-top: 10px;
  193. }
  194. </style>