fa-array-download.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <view class="fa-array-download">
  3. <view class="u-flex">
  4. <view class="u-flex-2"><view class="">来源</view></view>
  5. <view class="u-flex-7 u-p-l-10"><view class="">地址</view></view>
  6. <view class="u-flex-4 u-p-l-10"><view class="">密码</view></view>
  7. </view>
  8. <view class="u-flex u-m-t-15" v-for="(item, index) in list" :key="index">
  9. <view class="u-flex-2"><u-input v-model="item.name" :trim="trim" placeholder="来源" :border="border" :clearable="false" /></view>
  10. <view class="u-flex-6 u-m-l-10 u-m-r-10 "><u-input v-model="item.url" placeholder="请输入地址" :trim="trim" :border="border" /></view>
  11. <view class="u-p-l-10 u-p-r-10 u-m-r-10 u-text-center close" @click="uploadFile(index)">
  12. <u-icon name="arrow-upward" color="#ffffff" size="30"></u-icon>
  13. </view>
  14. <view class="u-flex-3 u-m-r-10 "><u-input placeholder="密码" v-model="item.password" :trim="trim" :border="border" /></view>
  15. <view class="u-p-l-10 u-p-r-10 u-text-center close" @click="del(index)"><u-icon name="close" color="#ffffff" size="30"></u-icon></view>
  16. </view>
  17. <view class="u-text-right u-m-t-20">
  18. <u-button
  19. size="mini"
  20. type="primary"
  21. :custom-style="{ backgroundColor: lightColor, color: theme.bgColor, border: '1px solid ' + faBorderColor }"
  22. throttle-time="0"
  23. @click="add"
  24. >
  25. <u-icon name="plus" :color="theme.bgColor" size="25"></u-icon>
  26. <text class="u-m-l-5">追加</text>
  27. </u-button>
  28. </view>
  29. <fa-upload-file ref="file" @success="uploadSuccess"></fa-upload-file>
  30. </view>
  31. </template>
  32. <script>
  33. import Emitter from '@/uni_modules/uview-ui/libs/util/emitter.js';
  34. import FaUploadFile from '../fa-upload-file/fa-upload-file.vue'
  35. export default {
  36. name: 'fa-array-download',
  37. components:{FaUploadFile},
  38. mixins: [Emitter],
  39. props: {
  40. contentList: {
  41. type: [Array, Object],
  42. default() {
  43. return [];
  44. }
  45. },
  46. showValue: {
  47. type: String,
  48. default() {
  49. return '';
  50. }
  51. }
  52. },
  53. watch: {
  54. contentList: {
  55. immediate: true,
  56. handler: function(val) {
  57. if (val) {
  58. let list = [];
  59. for (let i in val) {
  60. list.push({
  61. name: i,
  62. url: '',
  63. password: ''
  64. });
  65. }
  66. this.list = list;
  67. }
  68. }
  69. },
  70. list: {
  71. deep: true,
  72. handler: function(newValue) {
  73. let value = this.$u.test.empty(newValue)?'':JSON.stringify(newValue);
  74. this.$emit('input', value);
  75. setTimeout(() => {
  76. this.dispatch('u-form-item', 'on-form-blur', value);
  77. }, 50);
  78. }
  79. },
  80. showValue: {
  81. immediate: true,
  82. handler(val) {
  83. if (val) {
  84. this.list = JSON.parse(val);
  85. }
  86. }
  87. }
  88. },
  89. data() {
  90. return {
  91. border: true,
  92. trim: true,
  93. listIndex: 0,
  94. list: [
  95. {
  96. name: '',
  97. url: '',
  98. password: ''
  99. }
  100. ]
  101. };
  102. },
  103. methods: {
  104. add() {
  105. this.list.push({
  106. name: '',
  107. url: '',
  108. password: ''
  109. });
  110. },
  111. del(index) {
  112. this.list.splice(index, 1);
  113. },
  114. uploadFile(index) {
  115. this.listIndex = index;
  116. this.$refs.file.onUpload();
  117. },
  118. uploadSuccess(e) {
  119. this.$set(this.list[this.listIndex], 'url', e);
  120. },
  121. getData() {
  122. return this.list;
  123. }
  124. }
  125. };
  126. </script>
  127. <style lang="scss" scoped>
  128. .fa-array-download{
  129. width: 100%;
  130. }
  131. .close {
  132. background: #2c3e50;
  133. border-radius: 10rpx;
  134. }
  135. </style>