fileList.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view>
  3. <image src="https://cczdsz.cn/app/images/background.png" mode="" class="background"></image>
  4. <!-- <view class="" style="padding-top: 0rpx;">
  5. <!-- <back></back> -->
  6. <!-- </view> -->
  7. <view >
  8. <view>
  9. <u-search placeholder="请输入搜索内容" v-model="value1" shape="square" :show-action="false" :action-style="{'font-size':'40rpx'}" @search="gethosList()"></u-search>
  10. </view>
  11. <view v-for="(item,index) in list" :key="index" >
  12. <view class="project-content" @click="Downloads(item)">
  13. <view>
  14. <view class="font-forty-eight blue" style="font-size: 18px;">
  15. 文件名称:{{item.fileName}}
  16. </view>
  17. <view class="font-forty-eight blue" style="font-size: 20px;">
  18. 文件类型:{{item.fileSuffix}}
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. <u-mask :show="show" @click="show = false" width="100%" height="100%" >
  25. <u-image width="100%" height="300px" :src="src" class="makImage" ></u-image>
  26. </u-mask>
  27. <mypopup :show="show_loding" :popupText="popupText" :titleText="titleText" :cancelText="cancelText"
  28. :confirmText="confirmText" @close="cancel_loding" @confirm="confirm_loding">
  29. </mypopup>
  30. </view>
  31. </template>
  32. <script>
  33. import service from '@/api/index.js'
  34. import mypopup from '../../../components/mypopup.vue'
  35. export default {
  36. components:{
  37. mypopup
  38. },
  39. data() {
  40. return {
  41. show_loding: false,
  42. popupText: '', //对话框内容
  43. titleText: '',
  44. cancelText: '',
  45. confirmText: '',
  46. list:[],
  47. value:'',
  48. value1:'',
  49. nameValue:'',
  50. civilPower:'',
  51. userId:'',
  52. index:-1,
  53. ReachBottom:true,
  54. page:1,
  55. total:0,
  56. ranks:5,
  57. src:null,
  58. show:false,
  59. fileName:null,
  60. fileUrl:null
  61. }
  62. },
  63. onLoad(e) {
  64. this.nameValue = e.nameValue
  65. //this.getProjectList();
  66. this.getUserName();
  67. this.getFileList()
  68. uni.setNavigationBarTitle({
  69. title: '文件下载',
  70. });
  71. uni.setNavigationBarColor({
  72. frontColor: '#ffffff',
  73. backgroundColor: '#2d95f4',
  74. })
  75. },
  76. onTabItemTap(e)
  77. {
  78. console.log(e)
  79. uni.removeStorageSync('type')
  80. },
  81. onReachBottom(){
  82. console.log('触底')
  83. this.getReachBottom()
  84. },
  85. onPullDownRefresh()
  86. {
  87. console.log('下拉刷新')
  88. this.getReachBottom()
  89. },
  90. methods: {
  91. // getReachBottom()
  92. // {
  93. // if (this.ReachBottom) {
  94. // this.page+=1
  95. // this.getFileList()
  96. // }else
  97. // {
  98. // this.page=1
  99. // this.ReachBottom=false
  100. // }
  101. // },
  102. //取消按钮
  103. cancel_loding() {
  104. let _this = this;
  105. _this.show_loding = false;
  106. if (!_this.isEmpty(_this.fileUrl)) {
  107. uni.setClipboardData({
  108. data: _this.fileUrl,
  109. success() {
  110. uni.showToast({
  111. title: '已复制' + _this.fileName + '地址成功 请在浏览器打开',
  112. icon: 'none'
  113. });
  114. },
  115. fail(e) {
  116. uni.showToast({
  117. title: '复制失败',
  118. icon: 'none'
  119. });
  120. }
  121. });
  122. }
  123. },
  124. //确定按钮
  125. confirm_loding() {
  126. this.show_loding = false;
  127. this.download(this.fileUrl, this.fileName);
  128. },
  129. isEmpty(str) {
  130. return (!str || 0 === str.length);
  131. },
  132. getFileList()
  133. {
  134. service.getFileList(this.ranks).then(res=>{
  135. console.log('getProjectType', res)
  136. if(null==res){
  137. this.$UTILS.showPrompt('暂无可供下载文件!')
  138. return
  139. }
  140. let list1=[]
  141. // this.total=res.total
  142. // if(res.total>this.page*10)
  143. // {
  144. // this.ReachBottom=true
  145. // }else
  146. // {
  147. // this.ReachBottom=false
  148. // }
  149. list1=res
  150. this.list.push(...list1)
  151. })
  152. },
  153. getUserName(){
  154. service.getUserName().then(res=>{
  155. this.userId=res.id
  156. this.civilPower = res.civilPower;
  157. this.ranks=res.ranks
  158. })
  159. },
  160. //签订合同下载
  161. Downloads(item) {
  162. if(item.fileSuffix=='png'||item.fileSuffix=='jpg'||item.fileSuffix=='jpeg'||item.fileSuffix=='mp4'||item.fileSuffix=='dwg'||item.fileSuffix=='dwt')
  163. {
  164. this.src=item.url
  165. this.show=true
  166. }else
  167. {
  168. this.chooseModel(item.url,item.fileName)
  169. }
  170. },
  171. chooseModel(url, name) {
  172. this.cancelText = '复制';
  173. this.confirmText = "下载";
  174. this.titleText = "温馨提示"
  175. this.popupText = "下载或者复制链接";
  176. this.show_loding = true;
  177. this.fileName = name;
  178. this.fileUrl = url; //文件名称和下载地址赋值
  179. },
  180. getDownLoadFilePath() {
  181. let cachePath = `${uni.env.USER_DATA_PATH}/downloads`
  182. let fm = uni.getFileSystemManager()
  183. try {
  184. // 访问成功则存在
  185. fm.accessSync(cachePath)
  186. } catch (error) {
  187. // 不存在则新建
  188. fm.mkdirSync(cachePath, true)
  189. }
  190. return cachePath
  191. },
  192. download(url, name) {
  193. let savePath = this.getDownLoadFilePath();
  194. //var savePath = uni.env.USER_DATA_PATH + '/savePath'
  195. uni.downloadFile({
  196. url: url,
  197. success: response => {
  198. if (response.statusCode === 200) {
  199. uni.getFileSystemManager().saveFile({
  200. tempFilePath: response.tempFilePath,
  201. filePath: `${savePath}/${name}`,
  202. success: (resData) => {
  203. uni.showToast({
  204. title: '下载成功'
  205. })
  206. },
  207. fail: error => {}
  208. })
  209. }
  210. }
  211. })
  212. },
  213. }
  214. }
  215. </script>
  216. <style lang="scss" scoped>
  217. .background {
  218. z-index: -1;
  219. position: fixed;
  220. width: 100%;
  221. height: 100%;
  222. background-size: 100% 100%;
  223. }
  224. .project {
  225. border-radius: 72rpx;
  226. padding: 25rpx 0;
  227. text-align: center;
  228. margin: 170rpx 55rpx 0;
  229. }
  230. .project-content {
  231. border: 4rpx solid #3857F3;
  232. margin: 40rpx 55rpx 0;
  233. padding: 30rpx 20rpx;
  234. border-radius: 48rpx;
  235. }
  236. .position{
  237. position: absolute;
  238. bottom: 100rpx;
  239. right: 50rpx;
  240. .arrow{
  241. width: 152rpx;
  242. height: 152rpx;
  243. border-radius: 50%;
  244. padding: 25rpx;
  245. margin-left: 20rpx;
  246. }
  247. }
  248. .makImage{
  249. top:50%;
  250. left: 50%;
  251. text-align: center;
  252. }
  253. </style>