public.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /**
  2. *@des 公共接口
  3. *@author zhengjinyi
  4. *@date 2020/03/19 14:56:57
  5. *@param registerByPass
  6. */
  7. import requestUrl from '@/services/config.env.js'
  8. import request from '@/common/config/caimeiApi.js'
  9. import $reg from '@/common/config/common.js'
  10. /**
  11. * @新分类下的商品列表
  12. * @param:tinyTypeID 三级分类ID
  13. * @param:pageNum 页码
  14. * @param:pageSize 每页显示条数
  15. */
  16. export function searchQueryTinyType(url, params) {
  17. return new Promise(function(resolve, reject) {
  18. request.lodingGet(url, params, res => {
  19. if (res.code == 0) {
  20. resolve(res)
  21. } else {
  22. reject(res)
  23. }
  24. })
  25. })
  26. }
  27. /**
  28. *上传图片
  29. */
  30. export function uploadFileImage() {
  31. return new Promise(function(resolve, reject) {
  32. uni.chooseImage({
  33. count: 1, //默认1
  34. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  35. sourceType: ['camera','album'], //从相册选择
  36. success: (res) => {
  37. const tempFilePaths = res.tempFilePaths
  38. wx.showLoading({ title: '上传中~' })
  39. const uploadTask = uni.uploadFile({
  40. url: requestUrl + '/tools/image/upload/multi',
  41. filePath: tempFilePaths[0],
  42. name: 'file',
  43. header: {
  44. 'Content-Type': 'multipart/form-data',
  45. },
  46. formData: {
  47. 'user': 'test'
  48. },
  49. success: function(res) {
  50. wx.hideLoading()
  51. resolve(res)
  52. },
  53. error: function(error) {
  54. wx.hideLoading()
  55. reject(error)
  56. }
  57. })
  58. },
  59. fail: (error) =>{
  60. console.log('error',error)
  61. }
  62. })
  63. })
  64. }
  65. /**
  66. *上传文件
  67. * 限制pdf,doc,docx
  68. */
  69. export function uploadFilePdfDocDocx() {
  70. return new Promise(function(resolve, reject) {
  71. wx.chooseMessageFile({
  72. count: 1,
  73. type: 'file',
  74. success(res) {
  75. // tempFilePath可以作为img标签的src属性显示图片
  76. const tempFilePaths = res.tempFiles
  77. const size = tempFilePaths[0].size //获取图片的大小,单位B
  78. const filename = res.tempFiles[0].name
  79. const newfilename = filename + ''
  80. const url = requestUrl + '/tools/file/upload/oss'
  81. uni.setStorageSync('fileName', filename)
  82. console.log('filename', filename)
  83. //截取
  84. let fixFile = newfilename.substr(newfilename.lastIndexOf('.'))
  85. console.log(fixFile)
  86. //统一转成小写
  87. let lowFixFile = fixFile.toLowerCase()
  88. if (lowFixFile != '.pdf' && lowFixFile != '.doc' && lowFixFile != '.docx') { //限制了文件类型
  89. uni.showToast({
  90. title: '文件格式不正确!',
  91. icon: 'none',
  92. mask: true,
  93. duration: 3000
  94. })
  95. return
  96. }
  97. if (size > 51200000) { //限制了文件的大小50M
  98. uni.showToast({
  99. title: '文件大小不能超过50M',
  100. icon: 'none',
  101. mask: true,
  102. duration: 3000
  103. })
  104. return
  105. }
  106. wx.showLoading({ title: '上传中~' })
  107. wx.uploadFile({
  108. url: url,
  109. filePath: tempFilePaths[0].path,
  110. name: 'file',
  111. header: {
  112. 'Content-Type': 'multipart/form-data',
  113. },
  114. formData: {
  115. 'user': 'test'
  116. },
  117. success: function(res) {
  118. wx.hideLoading()
  119. resolve(res)
  120. },
  121. error: function(err) {
  122. wx.hideLoading()
  123. reject(err)
  124. }
  125. })
  126. }
  127. })
  128. })
  129. }
  130. /**
  131. *上传文件,仅限制PDF文件格式
  132. */
  133. export function uploadFilePdf() {
  134. return new Promise(function(resolve, reject) {
  135. wx.chooseMessageFile({
  136. count: 1,
  137. type: 'file',
  138. success(res) {
  139. // tempFilePath可以作为img标签的src属性显示图片
  140. const tempFilePaths = res.tempFiles
  141. const size = tempFilePaths[0].size //获取图片的大小,单位B
  142. const filename = res.tempFiles[0].name
  143. const newfilename = filename + ''
  144. const url = requestUrl + '/tools/file/upload/oss'
  145. uni.setStorageSync('fileName', filename)
  146. console.log('filename', filename)
  147. //截取
  148. let fixFile = newfilename.substr(newfilename.lastIndexOf('.'))
  149. console.log(fixFile)
  150. //统一转成小写
  151. let lowFixFile = fixFile.toLowerCase()
  152. if (lowFixFile != '.pdf') { //限制了文件类型
  153. uni.showToast({
  154. title: '文件必须为".pdf"格式!',
  155. icon: 'none',
  156. mask: true,
  157. duration: 3000
  158. })
  159. return
  160. }
  161. if (size > 20480000) { //限制了文件的大小20MB
  162. uni.showToast({
  163. title: '文件大小不能超过20M',
  164. icon: 'none',
  165. mask: true,
  166. duration: 3000
  167. })
  168. return
  169. }
  170. wx.showLoading({ title: '上传中~' })
  171. wx.uploadFile({
  172. url: url,
  173. filePath: tempFilePaths[0].path,
  174. name: 'file',
  175. header: {
  176. 'Content-Type': 'multipart/form-data',
  177. },
  178. formData: {
  179. 'user': 'test'
  180. },
  181. success: function(res) {
  182. wx.hideLoading()
  183. resolve(res)
  184. },
  185. error: function(err) {
  186. wx.hideLoading()
  187. reject(err)
  188. }
  189. })
  190. }
  191. })
  192. })
  193. }
  194. /**
  195. * 协销机构资料上传文件
  196. * 限制pdf,doc,docx
  197. */
  198. export function uploadFilePdfDocDocxXlsx() {
  199. debugger
  200. return new Promise(function(resolve, reject) {
  201. wx.chooseMessageFile({
  202. count: 1,
  203. type: 'file',
  204. success(res) {
  205. // tempFilePath可以作为img标签的src属性显示图片
  206. const tempFilePaths = res.tempFiles
  207. const size = tempFilePaths[0].size //获取图片的大小,单位B
  208. const filename = res.tempFiles[0].name
  209. const newfilename = filename + ''
  210. const url = requestUrl + '/tools/file/upload/oss'
  211. uni.setStorageSync('fileName', filename)
  212. console.log('filename', filename)
  213. //截取
  214. let fixFile = newfilename.substr(newfilename.lastIndexOf('.'))
  215. console.log(fixFile)
  216. //统一转成小写
  217. let lowFixFile = fixFile.toLowerCase()
  218. if (
  219. lowFixFile != '.pdf' &&
  220. lowFixFile != '.doc' &&
  221. lowFixFile != '.docx' &&
  222. lowFixFile != '.ppt' &&
  223. lowFixFile != '.pptx' &&
  224. lowFixFile != '.xlsx' &&
  225. lowFixFile != '.xls'
  226. ) { //限制了文件类型
  227. uni.showToast({
  228. title: '文件格式不正确!',
  229. icon: 'none',
  230. mask: true,
  231. duration: 3000
  232. })
  233. return
  234. }
  235. if (size > 51200000) { //限制了文件的大小50M
  236. uni.showToast({
  237. title: '文件大小不能超过50M',
  238. icon: 'none',
  239. mask: true,
  240. duration: 3000
  241. })
  242. return
  243. }
  244. wx.showLoading({ title: '上传中~' })
  245. wx.uploadFile({
  246. url: url,
  247. filePath: tempFilePaths[0].path,
  248. name: 'file',
  249. header: {
  250. 'Content-Type': 'multipart/form-data',
  251. },
  252. formData: {
  253. 'user': 'test'
  254. },
  255. success: function(res) {
  256. wx.hideLoading()
  257. resolve(res)
  258. },
  259. error: function(err) {
  260. wx.hideLoading()
  261. reject(err)
  262. }
  263. })
  264. }
  265. })
  266. })
  267. }