index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 class="url">{{ 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.code === 0) {
  55. res.data.records.map(i => this.list.push(i))
  56. this.hasMore = res.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.code === 0) {
  85. this.list = []
  86. this.listForm.pageNum = 1
  87. this.getList()
  88. this.form = [{
  89. name: "",
  90. url: ""
  91. }]
  92. }
  93. })
  94. } else {
  95. uni.showToast({
  96. title: '电台信息不能为空!',
  97. icon: 'none'
  98. })
  99. }
  100. },
  101. // 删除
  102. getDelete(item) {
  103. uni.showModal({
  104. title: '提示',
  105. content: `是否删除名称为${item.name}的电台?`,
  106. confirmColor: '#78B06A',
  107. success: (e) => {
  108. if (e.confirm) {
  109. remove({
  110. id: item.id,
  111. ...this.dev
  112. }).then(res => {
  113. if (res.code === 0) {
  114. this.list = []
  115. this.listForm.pageNum = 1
  116. this.getList(this.dev)
  117. }
  118. })
  119. }
  120. }
  121. })
  122. }
  123. },
  124. onReachBottom() {
  125. if(this.hasMore) {
  126. this.listForm.pageNum++
  127. this.getList()
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .plus {
  134. width: 160rpx;
  135. height: 70rpx;
  136. line-height: 70rpx;
  137. font-size: 28rpx;
  138. margin: 0;
  139. font-weight: bold;
  140. background: none;
  141. color: #FFF;
  142. border: 1px solid #FFF;
  143. }
  144. h1 {
  145. font-size: 16px;
  146. line-height: 50px;
  147. text-align: center;
  148. }
  149. h2 {
  150. font-size: 16px;
  151. line-height: 50px;
  152. }
  153. .list {
  154. .item {
  155. border: 1px solid #FFF;
  156. border-radius: 8px;
  157. padding: 20px 30px 20px 20px;
  158. display: flex;
  159. flex-direction: column;
  160. justify-content: space-around;
  161. position: relative;
  162. margin-bottom: 15px;
  163. background-color: #FFF;
  164. color: #000;
  165. .delete {
  166. position: absolute;
  167. right: 10px;
  168. transform: rotate(90deg);
  169. }
  170. .url{
  171. white-space: nowrap;
  172. overflow: hidden;
  173. text-overflow: ellipsis;
  174. }
  175. }
  176. }
  177. .form {
  178. display: flex;
  179. flex-direction: column;
  180. justify-content: center;
  181. margin: 8px 0;
  182. border: 1px solid #FFF;
  183. padding: 20px;
  184. border-radius: 8px;
  185. position: relative;
  186. uni-input {
  187. background-color: #FFF;
  188. color: #000;
  189. }
  190. .close {
  191. position: absolute;
  192. right: 10px;
  193. top: 10px;
  194. }
  195. }
  196. .submit {
  197. height: 80rpx;
  198. line-height: 80rpx;
  199. margin-top: 10px;
  200. }
  201. </style>