upload-file.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <view class="uni-file-picker__files">
  3. <view v-if="!readonly" class="files-button" @click="choose">
  4. <slot></slot>
  5. </view>
  6. <!-- :class="{'is-text-box':showType === 'list'}" -->
  7. <!-- <view v-if="list.length > 0" class="uni-file-picker__lists is-text-box" :style="borderStyle"> -->
  8. <!-- ,'is-list-card':showType === 'list-card' -->
  9. <!-- <view class="uni-file-picker__lists-box" v-for="(item ,index) in list" :key="index" :class="{ -->
  10. <!-- 'files-border':index !== 0 && styles.dividline}" -->
  11. <!-- :style="index !== 0 && styles.dividline &&borderLineStyle"> -->
  12. <!-- <view class="uni-file-picker__item"> -->
  13. <!-- :class="{'is-text-image':showType === 'list'}" -->
  14. <!-- <view class="files__image is-text-image">
  15. <image class="header-image" :src="item.logo" mode="aspectFit"></image>
  16. </view> -->
  17. <!-- <view class="files__name">{{item.name}}</view> -->
  18. <!-- <view v-if="delIcon&&!readonly" class="icon-del-box icon-files" @click="delFile(index)"> -->
  19. <!-- <view class="icon-del icon-files"></view> -->
  20. <!-- <view class="icon-del rotate"></view> -->
  21. <!-- </view> -->
  22. <!-- </view> -->
  23. <!-- <view v-if="(item.progress && item.progress !== 100) ||item.progress===0 " class="file-picker__progress"> -->
  24. <!-- <progress class="file-picker__progress-item" :percent="item.progress === -1?0:item.progress" stroke-width="4" -->
  25. <!-- :backgroundColor="item.errMsg?'#ff5a5f':'#EBEBEB'" /> -->
  26. <!-- </view> -->
  27. <!-- <view v-if="item.status === 'error'" class="file-picker__mask" @click.stop="uploadFiles(item,index)"> -->
  28. <!-- 点击重试 -->
  29. <!-- </view> -->
  30. <!-- </view> -->
  31. <!-- </view> -->
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. name: "uploadFile",
  37. props: {
  38. filesList: {
  39. type: Array,
  40. default () {
  41. return []
  42. }
  43. },
  44. delIcon: {
  45. type: Boolean,
  46. default: true
  47. },
  48. limit: {
  49. type: [Number, String],
  50. default: 9
  51. },
  52. showType: {
  53. type: String,
  54. default: ''
  55. },
  56. listStyles: {
  57. type: Object,
  58. default () {
  59. return {
  60. // 是否显示边框
  61. border: true,
  62. // 是否显示分隔线
  63. dividline: true,
  64. // 线条样式
  65. borderStyle: {}
  66. }
  67. }
  68. },
  69. readonly:{
  70. type:Boolean,
  71. default:false
  72. }
  73. },
  74. computed: {
  75. list() {
  76. let files = []
  77. this.filesList.forEach(v => {
  78. files.push(v)
  79. })
  80. return files
  81. },
  82. styles() {
  83. let styles = {
  84. border: true,
  85. dividline: true,
  86. 'border-style': {}
  87. }
  88. return Object.assign(styles, this.listStyles)
  89. },
  90. borderStyle() {
  91. let {
  92. borderStyle,
  93. border
  94. } = this.styles
  95. let obj = {}
  96. if (!border) {
  97. obj.border = 'none'
  98. } else {
  99. let width = (borderStyle && borderStyle.width) || 1
  100. width = this.value2px(width)
  101. let radius = (borderStyle && borderStyle.radius) || 5
  102. radius = this.value2px(radius)
  103. obj = {
  104. 'border-width': width,
  105. 'border-style': (borderStyle && borderStyle.style) || 'solid',
  106. 'border-color': (borderStyle && borderStyle.color) || '#eee',
  107. 'border-radius': radius
  108. }
  109. }
  110. let classles = ''
  111. for (let i in obj) {
  112. classles += `${i}:${obj[i]};`
  113. }
  114. return classles
  115. },
  116. borderLineStyle() {
  117. let obj = {}
  118. let {
  119. borderStyle
  120. } = this.styles
  121. if (borderStyle && borderStyle.color) {
  122. obj['border-color'] = borderStyle.color
  123. }
  124. if (borderStyle && borderStyle.width) {
  125. let width = borderStyle && borderStyle.width || 1
  126. let style = borderStyle && borderStyle.style || 0
  127. if (typeof width === 'number') {
  128. width += 'px'
  129. } else {
  130. width = width.indexOf('px') ? width : width + 'px'
  131. }
  132. obj['border-width'] = width
  133. if (typeof style === 'number') {
  134. style += 'px'
  135. } else {
  136. style = style.indexOf('px') ? style : style + 'px'
  137. }
  138. obj['border-top-style'] = style
  139. }
  140. let classles = ''
  141. for (let i in obj) {
  142. classles += `${i}:${obj[i]};`
  143. }
  144. return classles
  145. }
  146. },
  147. methods: {
  148. uploadFiles(item, index) {
  149. console.log(item)
  150. this.$emit("uploadFiles", {
  151. item,
  152. index
  153. })
  154. },
  155. choose() {
  156. this.$emit("choose")
  157. },
  158. delFile(index) {
  159. this.$emit('delFile', index)
  160. },
  161. value2px(value) {
  162. if (typeof value === 'number') {
  163. value += 'px'
  164. } else {
  165. value = value.indexOf('px') !== -1 ? value : value + 'px'
  166. }
  167. return value
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss">
  173. .uni-file-picker__files {
  174. /* #ifndef APP-NVUE */
  175. display: flex;
  176. /* #endif */
  177. flex-direction: column;
  178. justify-content: flex-start;
  179. }
  180. .files-button {
  181. // border: 1px red solid;
  182. }
  183. .uni-file-picker__lists {
  184. position: relative;
  185. margin-top: 5px;
  186. overflow: hidden;
  187. }
  188. .file-picker__mask {
  189. /* #ifndef APP-NVUE */
  190. display: flex;
  191. /* #endif */
  192. justify-content: center;
  193. align-items: center;
  194. position: absolute;
  195. right: 0;
  196. top: 0;
  197. bottom: 0;
  198. left: 0;
  199. color: #fff;
  200. font-size: 14px;
  201. background-color: rgba(0, 0, 0, 0.4);
  202. }
  203. .uni-file-picker__lists-box {
  204. position: relative;
  205. }
  206. .uni-file-picker__item {
  207. /* #ifndef APP-NVUE */
  208. display: flex;
  209. /* #endif */
  210. align-items: center;
  211. padding: 8px 10px;
  212. padding-right: 5px;
  213. padding-left: 10px;
  214. }
  215. .files-border {
  216. border-top: 1px #eee solid;
  217. }
  218. .files__name {
  219. flex: 1;
  220. font-size: 14px;
  221. color: #666;
  222. margin-right: 25px;
  223. /* #ifndef APP-NVUE */
  224. word-break: break-all;
  225. word-wrap: break-word;
  226. /* #endif */
  227. }
  228. .icon-files {
  229. /* #ifndef APP-NVUE */
  230. position: static;
  231. background-color: initial;
  232. /* #endif */
  233. }
  234. // .icon-files .icon-del {
  235. // background-color: #333;
  236. // width: 12px;
  237. // height: 1px;
  238. // }
  239. .is-list-card {
  240. border: 1px #eee solid;
  241. margin-bottom: 5px;
  242. border-radius: 5px;
  243. box-shadow: 0 0 2px 0px rgba(0, 0, 0, 0.1);
  244. padding: 5px;
  245. }
  246. .files__image {
  247. width: 40px;
  248. height: 40px;
  249. margin-right: 10px;
  250. }
  251. .header-image {
  252. width: 100%;
  253. height: 100%;
  254. }
  255. .is-text-box {
  256. border: 1px #eee solid;
  257. border-radius: 5px;
  258. }
  259. .is-text-image {
  260. width: 25px;
  261. height: 25px;
  262. margin-left: 5px;
  263. }
  264. .rotate {
  265. position: absolute;
  266. transform: rotate(90deg);
  267. }
  268. .icon-del-box {
  269. /* #ifndef APP-NVUE */
  270. display: flex;
  271. margin: auto 0;
  272. /* #endif */
  273. align-items: center;
  274. justify-content: center;
  275. position: absolute;
  276. top: 0px;
  277. bottom: 0;
  278. right: 5px;
  279. height: 26px;
  280. width: 26px;
  281. // border-radius: 50%;
  282. // background-color: rgba(0, 0, 0, 0.5);
  283. z-index: 2;
  284. transform: rotate(-45deg);
  285. }
  286. .icon-del {
  287. width: 15px;
  288. height: 1px;
  289. background-color: #333;
  290. // border-radius: 1px;
  291. }
  292. /* #ifdef H5 */
  293. @media all and (min-width: 768px) {
  294. .uni-file-picker__files {
  295. max-width: 375px;
  296. }
  297. }
  298. /* #endif */
  299. </style>