123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- /**
- *@des 公共接口
- *@author zhengjinyi
- *@date 2020/03/19 14:56:57
- *@param registerByPass
- */
- import requestUrl from '@/services/ajax.env.js'
- import request from '@/common/config/caimeiApi.js'
- import $reg from '@/common/config/common.js'
- /**
- * @新分类下的商品列表
- * @param:tinyTypeID 三级分类ID
- * @param:pageNum 页码
- * @param:pageSize 每页显示条数
- */
- export function searchQueryTinyType(url,params) {
- return new Promise(function(resolve,reject) {
- request.lodingGet(url,params, res => {
- if(res.code == 0){
- resolve(res);
- }else{
- reject(res)
- }
- })
- });
- }
- /**
- *上传图片
- */
- export function uploadFileImage() {
- return new Promise(function(resolve,reject) {
- uni.chooseImage({
- count: 1, //默认1
- sizeType: ['original','compressed'], //可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album'], //从相册选择
- success: (res) => {
- const tempFilePaths = res.tempFilePaths;
- wx.showLoading({ title: '上传中~' })
- const uploadTask = uni.uploadFile({
- url : requestUrl+'/formData/MultiPictareaddData',
- filePath: tempFilePaths[0],
- name: 'file',
- header: {
- "Content-Type": "multipart/form-data",
- },
- formData: {
- 'user': 'test'
- },
- success: function (res) {
- wx.hideLoading()
- resolve(res);
- },
- error : function(e){
- wx.hideLoading()
- reject(res)
- }
- })
- }
- });
- });
- }
- /**
- *上传文件
- * 限制pdf,doc,docx
- */
- export function uploadFilePdfDocDocx() {
- return new Promise(function(resolve,reject) {
- wx.chooseMessageFile({
- count: 1,
- type: 'file',
- success (res) {
- // tempFilePath可以作为img标签的src属性显示图片
- const tempFilePaths = res.tempFiles
- const size = tempFilePaths[0].size;//获取图片的大小,单位B
- const filename = res.tempFiles[0].name;
- const newfilename = filename + "";
- const url = requestUrl+'/file/upload';
- uni.setStorageSync('fileName',filename)
- console.log('filename',filename)
- //截取
- let fixFile = newfilename.substr(newfilename.lastIndexOf('.'));
- console.log(fixFile);
- //统一转成小写
- let lowFixFile = fixFile.toLowerCase();
- if ( lowFixFile != '.pdf' && lowFixFile != '.doc' && lowFixFile != '.docx' ){ //限制了文件类型
- uni.showToast({
- title: '文件格式不正确!',
- icon:'none',
- mask:true,
- duration: 3000
- });
- return;
- }
- if(size > 51200000){//限制了文件的大小50M
- uni.showToast({
- title: '文件大小不能超过50M',
- icon:'none',
- mask:true,
- duration: 3000
- });
- return;
- }
- wx.showLoading({ title: '上传中~' })
- wx.uploadFile({
- url : url,
- filePath: tempFilePaths[0].path,
- name: 'file',
- header: {
- "Content-Type": "multipart/form-data",
- },
- formData: {
- 'user': 'test'
- },
- success: function (res) {
- wx.hideLoading()
- resolve(res);
- },
- error : function(err){
- wx.hideLoading()
- reject(err)
- }
- })
- }
- })
- });
- }
- /**
- *上传文件,仅限制PDF文件格式
- */
- export function uploadFilePdf() {
- return new Promise(function(resolve,reject) {
- wx.chooseMessageFile({
- count: 1,
- type: 'file',
- success (res) {
- // tempFilePath可以作为img标签的src属性显示图片
- const tempFilePaths = res.tempFiles
- const size = tempFilePaths[0].size;//获取图片的大小,单位B
- const filename = res.tempFiles[0].name;
- const newfilename = filename + "";
- const url = requestUrl+'/file/upload';
- uni.setStorageSync('fileName',filename)
- console.log('filename',filename)
- //截取
- let fixFile = newfilename.substr(newfilename.lastIndexOf('.'));
- console.log(fixFile);
- //统一转成小写
- let lowFixFile = fixFile.toLowerCase();
- if ( lowFixFile != '.pdf' ){ //限制了文件类型
- uni.showToast({
- title: '文件必须为".pdf"格式!',
- icon:'none',
- mask:true,
- duration: 3000
- });
- return;
- }
- if( size > 20480000 ){//限制了文件的大小20MB
- uni.showToast({
- title: '文件大小不能超过20M',
- icon:'none',
- mask:true,
- duration: 3000
- });
- return;
- }
- wx.showLoading({ title: '上传中~' })
- wx.uploadFile({
- url : url,
- filePath: tempFilePaths[0].path,
- name: 'file',
- header: {
- "Content-Type": "multipart/form-data",
- },
- formData: {
- 'user': 'test'
- },
- success: function (res) {
- wx.hideLoading()
- resolve(res);
- },
- error : function(err){
- wx.hideLoading()
- reject(err)
- }
- })
- }
- })
- });
- }
|