feat: move project
This commit is contained in:
commit
4a940f28ba
97 changed files with 5047 additions and 0 deletions
405
pages/takephoto/takephoto.js
Normal file
405
pages/takephoto/takephoto.js
Normal file
|
|
@ -0,0 +1,405 @@
|
|||
import R from '../../utils/request';
|
||||
import C from '../../utils/constant';
|
||||
Page({
|
||||
data: {
|
||||
cdnHost: C.cdnHost,
|
||||
cdnHost: C.cdnHost,
|
||||
title: '',
|
||||
tel: '',
|
||||
content: '',
|
||||
shortAddress: '',
|
||||
address: '',
|
||||
video: '',
|
||||
position: {
|
||||
longitude: 0,
|
||||
latitude: 0,
|
||||
},
|
||||
ds: {
|
||||
list: [],
|
||||
refStatusNum: { finished: 0, failed: 0, process: 0 },
|
||||
},
|
||||
ts: {
|
||||
refImgDescs: {},
|
||||
refImgKeywords: {},
|
||||
fileUploadList: [],
|
||||
fileUploadList2: [],
|
||||
isUploading: false,
|
||||
timer: [],
|
||||
},
|
||||
stop: false,
|
||||
gridConfig: {
|
||||
column: 4,
|
||||
width: 160,
|
||||
height: 160,
|
||||
},
|
||||
config: {
|
||||
count: 1,
|
||||
},
|
||||
phoneError: false,
|
||||
//
|
||||
videoFileList: [],
|
||||
},
|
||||
onLoad(options) {
|
||||
const that = this;
|
||||
R.get('/index.php/api/v1/my', {}).then(({ model }) => {
|
||||
this.setData({ tel: model.phone });
|
||||
});
|
||||
wx.getFuzzyLocation({
|
||||
type: 'wgs84',
|
||||
success(res) {
|
||||
const longitude = res.longitude
|
||||
const latitude = res.latitude
|
||||
that.setData({
|
||||
position: {
|
||||
longitude,
|
||||
latitude,
|
||||
},
|
||||
});
|
||||
R.get('/index.php/api/v1/gps', { lat: latitude, lon: longitude }).then(({ model }) => {
|
||||
that.setData({ shortAddress: model.short_ad, address: model.full_ad });
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
onUnload() {
|
||||
this.data.stop = true;
|
||||
},
|
||||
onShareAppMessage() {
|
||||
},
|
||||
choosePoi() {
|
||||
const that = this;
|
||||
wx.chooseLocation({
|
||||
success({ latitude, longitude, name, address }) {
|
||||
that.setData({
|
||||
position: {
|
||||
latitude,
|
||||
longitude,
|
||||
},
|
||||
shortAddress: name,
|
||||
address,
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
//
|
||||
onPhoneInput(e) {
|
||||
const { phoneError } = this.data;
|
||||
const isPhoneNumber = /^[1][3,4,5,7,8,9][0-9]{9}$/.test(e.detail.value);
|
||||
if (phoneError === isPhoneNumber) {
|
||||
this.setData({
|
||||
phoneError: !isPhoneNumber,
|
||||
});
|
||||
}
|
||||
},
|
||||
onSubmit() {
|
||||
console.log('this.stat', this.data);
|
||||
const { title, tel, shortAddress, address, position, ds, content, videoFileList } = this.data;
|
||||
if (ds.refStatusNum.failed > 0) {
|
||||
wx.showToast({
|
||||
title: '请处理上传失败的图片',
|
||||
icon: 'none',
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (ds.refStatusNum.process > 0) {
|
||||
wx.showToast({
|
||||
title: '请等待图片上传完成',
|
||||
icon: 'none',
|
||||
});
|
||||
return;
|
||||
}
|
||||
// 每个属性都判空,并且给出toast提示
|
||||
if (!tel) {
|
||||
wx.showToast({
|
||||
title: '请输入手机号',
|
||||
icon: 'none',
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!title) {
|
||||
wx.showToast({
|
||||
title: '请输入标题',
|
||||
icon: 'none',
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!content) {
|
||||
wx.showToast({
|
||||
title: '请输入您的发件信息',
|
||||
icon: 'none',
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!shortAddress) {
|
||||
wx.showToast({
|
||||
title: '请选择位置',
|
||||
icon: 'none',
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (ds.list.length === 0) {
|
||||
wx.showToast({
|
||||
title: '请上传图片',
|
||||
icon: 'none',
|
||||
});
|
||||
return;
|
||||
}
|
||||
// 提交数据
|
||||
R.post('/index.php/api/v1/submit', {
|
||||
title,
|
||||
tel,
|
||||
shortAddress,
|
||||
address,
|
||||
content,
|
||||
longitude: position.longitude,
|
||||
latitude: position.latitude,
|
||||
imgs: ds.list.map((o) => o.path),
|
||||
video: videoFileList && videoFileList.length > 0 ? videoFileList[0].path : undefined,
|
||||
}).then(({ model }) => {
|
||||
wx.showToast({
|
||||
title: '提交成功,感谢您的反馈',
|
||||
icon: 'success',
|
||||
});
|
||||
setTimeout(() => {
|
||||
wx.navigateBack();
|
||||
}, 1000);
|
||||
});
|
||||
},
|
||||
goBack() {
|
||||
wx.navigateBack();
|
||||
},
|
||||
//
|
||||
callStatusNum() {
|
||||
const { ds } = this.data;
|
||||
const s = { finished: 0, failed: 0, process: 0 };
|
||||
ds.list.forEach((o) => {
|
||||
if (o.failed) s.failed++;
|
||||
else if (o.finished) s.finished++;
|
||||
else s.process++;
|
||||
});
|
||||
this.setData({
|
||||
'ds.refStatusNum': s,
|
||||
});
|
||||
},
|
||||
imgHandleSuccess(e) {
|
||||
console.log('imgHandleSuccess', e.detail);
|
||||
// const { files } = e.detail;
|
||||
// this.setData({
|
||||
// originFiles: files,
|
||||
// });
|
||||
this.httpRequest();
|
||||
},
|
||||
imgHandleRemove(e) {
|
||||
const { index } = e.detail;
|
||||
console.log('imgHandleRemove', e.detail);
|
||||
const { ds } = this.data;
|
||||
ds.list.splice(index, 1);
|
||||
this.setData({
|
||||
'ds.list': ds.list,
|
||||
});
|
||||
},
|
||||
imgHandleClick(e) {
|
||||
console.log(e.detail.file);
|
||||
},
|
||||
beforUpload(e) {
|
||||
const { files } = e.detail;
|
||||
console.log('beforUpload', files);
|
||||
const { ts } = this.data;
|
||||
const { fileUploadList, fileUploadList2 } = ts;
|
||||
files.map((file) => {
|
||||
fileUploadList.push(file);
|
||||
fileUploadList2.push(file);
|
||||
})
|
||||
this.setData({
|
||||
'ts.fileUploadList': fileUploadList,
|
||||
'ts.fileUploadList2': fileUploadList2,
|
||||
});
|
||||
},
|
||||
startPreview() {
|
||||
console.log('startPreview');
|
||||
if (this.data.stop) return;
|
||||
const { ts, ds } = this.data;
|
||||
const { fileUploadList2 } = ts;
|
||||
if (fileUploadList2.length > 0) {
|
||||
const file = fileUploadList2.shift();
|
||||
ds.list.push({
|
||||
src: file.url,
|
||||
url: file.url,
|
||||
uid: file.name,
|
||||
name: file.name,
|
||||
percent: 0,
|
||||
failed: false,
|
||||
status: 'loading',
|
||||
})
|
||||
this.setData({
|
||||
'ts.fileUploadList2': fileUploadList2,
|
||||
'ds.list': ds.list,
|
||||
});
|
||||
setTimeout(() => {
|
||||
this.startPreview();
|
||||
}, 0);
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
this.startPreview();
|
||||
}, 2000);
|
||||
}
|
||||
},
|
||||
httpRequest(e) {
|
||||
if (this.data.stop) return;
|
||||
const { ts } = this.data;
|
||||
if (ts.isUploading) return;
|
||||
ts.isUploading = true;
|
||||
console.log('httpRequest');
|
||||
// 循环检测 是否有文件可以上传
|
||||
setTimeout(() => {
|
||||
this.uploadHandle();
|
||||
this.startPreview();
|
||||
}, 0);
|
||||
},
|
||||
uploadHandle() {
|
||||
console.log('uploadHandle');
|
||||
if (this.data.stop) return;
|
||||
this.callStatusNum();
|
||||
const { ts, ds } = this.data;
|
||||
const { fileUploadList } = ts;
|
||||
if (fileUploadList.length > 0) {
|
||||
console.log('fileUploadList', fileUploadList);
|
||||
const file = fileUploadList.shift();
|
||||
// formData.append('imageData', file);
|
||||
R.upload({ a: 1 }, 'img_file', file.url).catch((e) => e).then((response) => {
|
||||
// console.log('response-response333', response);
|
||||
ts.isUploading = false;
|
||||
try {
|
||||
response.data = JSON.parse(response.data);
|
||||
} catch (error) {
|
||||
response.data = null;
|
||||
}
|
||||
// console.log('asdfasd-response', response.data);
|
||||
if (response.data && response.data.code == -1000) {
|
||||
wx.showToast({
|
||||
title: '登录超时,请重新登录',
|
||||
icon: 'none',
|
||||
});
|
||||
setTimeout(() => {
|
||||
wx.navigateTo({ url: '/pages/home/home' });
|
||||
}, 500)
|
||||
return;
|
||||
}
|
||||
else if (response.data && response.data.success) {
|
||||
console.log('asdfasd-response2222', response.data);
|
||||
const { data: { model: { path } } } = response;
|
||||
this.setData({
|
||||
'ds.list': ds.list.map((o) => {
|
||||
if (file.name == o.uid) {
|
||||
return { ...o, path, finished: true, percent: 100, status: 'done' };
|
||||
}
|
||||
return { ...o };
|
||||
})
|
||||
});
|
||||
// this.setData({
|
||||
// [`ds.list[${idx}].url`]: C.cdnHost + path,
|
||||
// });
|
||||
// R.getImg(4, imageId).then((path) => {
|
||||
// const tlist = this.data.ds.list;
|
||||
// let idx = 0;
|
||||
// // console.log('path', path);
|
||||
// tlist.forEach((c, i) => {
|
||||
// if (c.imageId == imageId) {
|
||||
// idx = i;
|
||||
// }
|
||||
// });
|
||||
// if (idx) {
|
||||
// this.setData({
|
||||
// [`ds.list[${idx}].url`]: path,
|
||||
// });
|
||||
// }
|
||||
// })
|
||||
// wx.showToast({
|
||||
// title: '图片:' + file.name + '已暂存',
|
||||
// icon: 'success',
|
||||
// });
|
||||
// this.saveTmpData();
|
||||
} else {
|
||||
console.log(response, file.name);
|
||||
let errorMsg = '上传失败,请移除后重试';
|
||||
// if (response.data && response.data.status == 529) {
|
||||
// errorMsg = '其他图集中已存在,请移除';
|
||||
// }
|
||||
this.setData({
|
||||
'ds.list': ds.list.map((o) => {
|
||||
if (file.name == o.uid) {
|
||||
return { ...o, failed: errorMsg, status: 'failed' };
|
||||
}
|
||||
return { ...o };
|
||||
}),
|
||||
});
|
||||
wx.showToast({
|
||||
title: file.name + ',' + errorMsg,
|
||||
icon: 'error',
|
||||
});
|
||||
// this.saveTmpData();
|
||||
}
|
||||
setTimeout(() => {
|
||||
this.uploadHandle();
|
||||
}, 0);
|
||||
});
|
||||
} else {
|
||||
// setTimeout(() => {
|
||||
// this.uploadHandle();
|
||||
// }, 2000);
|
||||
}
|
||||
},
|
||||
//video
|
||||
handleVideoAdd(e) {
|
||||
const { files } = e.detail;
|
||||
files.forEach(file => this.uploadVideoFile(file))
|
||||
},
|
||||
uploadVideoFile(file) {
|
||||
|
||||
wx.getVideoInfo({ src: file.url }).then((res) => {
|
||||
if (res.duration > 180) {
|
||||
wx.showToast({
|
||||
title: '视频时长不能超过3分钟',
|
||||
icon: 'none',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
const { videoFileList } = this.data;
|
||||
|
||||
this.setData({
|
||||
videoFileList: [...videoFileList, { ...file, path: '', status: 'loading' }],
|
||||
});
|
||||
const { length } = videoFileList;
|
||||
R.upload({ a: 2 }, 'video_file', file.url, (res) => {
|
||||
this.setData({
|
||||
[`videoFileList[${length}].percent`]: res.progress,
|
||||
});
|
||||
}).catch((e) => e).then((response) => {
|
||||
try {
|
||||
response.data = JSON.parse(response.data);
|
||||
} catch (error) {
|
||||
response.data = null;
|
||||
}
|
||||
if (response.data && response.data.success) {
|
||||
const { data: { model: { path } } } = response;
|
||||
console.log('asdfasd-response2222', response.data, this.data.videoFileList, length);
|
||||
this.setData({
|
||||
[`videoFileList[${length}].status`]: 'done',
|
||||
[`videoFileList[${length}].path`]: path,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
handleVideoRemove(e) {
|
||||
const { index } = e.detail;
|
||||
const { videoFileList } = this.data;
|
||||
|
||||
videoFileList.splice(index, 1);
|
||||
this.setData({
|
||||
videoFileList,
|
||||
});
|
||||
},
|
||||
})
|
||||
14
pages/takephoto/takephoto.json
Normal file
14
pages/takephoto/takephoto.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"navigationBarTitleText": "有发现",
|
||||
"backgroundTextStyle": "light",
|
||||
"usingComponents": {
|
||||
"t-image": "tdesign-miniprogram/image/image",
|
||||
"t-input": "tdesign-miniprogram/input/input",
|
||||
"t-cell": "tdesign-miniprogram/cell/cell",
|
||||
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||
"t-notice-bar": "tdesign-miniprogram/notice-bar/notice-bar",
|
||||
"t-upload": "tdesign-miniprogram/upload/upload",
|
||||
"t-button": "tdesign-miniprogram/button/button",
|
||||
"t-textarea": "tdesign-miniprogram/textarea/textarea"
|
||||
}
|
||||
}
|
||||
35
pages/takephoto/takephoto.wxml
Normal file
35
pages/takephoto/takephoto.wxml
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<view>
|
||||
<image class="img" src="{{cdnHost + '/static/bg_take.jpeg?v=5'}}" />
|
||||
<!-- <view class="img"> -->
|
||||
<!-- <view>发布信息审核通过后获10元红包</view> -->
|
||||
<!-- </view> -->
|
||||
<view class="form">
|
||||
<t-input label="标题" placeholder="请输入您的发现标题" model:value="{{title}}" align="right" />
|
||||
<t-input label="手机" type="number" tips="{{phoneError ? '手机号输入不正确' : ''}}" bindchange="onPhoneInput" placeholder="请输入您的手机号码" model:value="{{tel}}" align="right" />
|
||||
<t-cell title="现场图片" description="最多6张图片" hover></t-cell>
|
||||
<t-cell class="photos">
|
||||
<view class="wrapper" slot="description">
|
||||
<t-upload max="{{6}}" size-limit="{{102400}}" media-type="{{['image']}}" files="{{ds.list}}" gridConfig="{{gridConfig}}" bind:success="imgHandleSuccess" bind:remove="imgHandleRemove" bind:click="imgHandleClick" request-method="{{httpRequest}}" bind:add="beforUpload" />
|
||||
</view>
|
||||
</t-cell>
|
||||
<t-cell title="现场视频(可选)" description="最多一个视频(3分钟内)" hover>
|
||||
<t-upload slot="note" mediaType="{{['video']}}" max="{{1}}" files="{{videoFileList}}" bind:add="handleVideoAdd" bind:remove="handleVideoRemove"></t-upload>
|
||||
</t-cell>
|
||||
<t-textarea t-class="external-class" label="" placeholder="请输入具体内容" value="" maxcharacter="5000" disableDefaultPadding="{{true}}" model:value="{{content}}" />
|
||||
<view class="local_bar">
|
||||
<view class="local">
|
||||
<t-icon name="location-1" size="30rpx" color="green"></t-icon>
|
||||
{{shortAddress}}
|
||||
</view>
|
||||
<view class="btn" bind:tap="choosePoi">
|
||||
修正位置
|
||||
<t-icon name="chevron-right" size="28rpx"></t-icon>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<t-notice-bar visible="{{true}}" theme="warning" content="请确保您发布的信息真实有效"></t-notice-bar>
|
||||
<view class="btns">
|
||||
<t-button theme="primary" size="large" block bind:tap="onSubmit">确认发布</t-button>
|
||||
<t-button theme="primary" size="large" block variant="outline" bind:tap="goBack">取消</t-button>
|
||||
</view>
|
||||
</view>
|
||||
93
pages/takephoto/takephoto.wxss
Normal file
93
pages/takephoto/takephoto.wxss
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
page {
|
||||
background-color: rgb(245, 246, 247);
|
||||
}
|
||||
|
||||
.img {
|
||||
font-size: 12rpx;
|
||||
width: 750rpx;
|
||||
margin: 0 auto;
|
||||
height: 530rpx;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.form {
|
||||
margin: 0 20rpx;
|
||||
border-radius: 4px;
|
||||
background-color: #fff;
|
||||
margin-top: -100rpx;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.form .t-input__label {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.form .t-input__label::after {
|
||||
display: block;
|
||||
content: '*';
|
||||
color: #f00;
|
||||
position: absolute;
|
||||
font-size: 40rpx;
|
||||
right: -30rpx;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.form .photos .t-image {
|
||||
margin-left: 20rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.t-textarea__wrapper {
|
||||
background-color: rgb(245, 246, 247);
|
||||
border: 16rpx;
|
||||
}
|
||||
|
||||
.t-textarea__wrapper .t-textarea__wrapper-inner {
|
||||
padding: 16rpx;
|
||||
border: 16rpx;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.local_bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 40rpx;
|
||||
border-bottom: 10px solid #fff;
|
||||
}
|
||||
|
||||
.local_bar .t-icon {
|
||||
margin-right: 10rpx;
|
||||
}
|
||||
|
||||
.local_bar .local {
|
||||
display: flex;
|
||||
font-size: 24rpx;
|
||||
align-items: center;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.local_bar .btn {
|
||||
display: flex;
|
||||
font-size: 24rpx;
|
||||
align-items: center;
|
||||
color: blue;
|
||||
}
|
||||
|
||||
.t-notice-bar {
|
||||
background: none !important;
|
||||
}
|
||||
|
||||
.btns {
|
||||
padding: 0 40rpx;
|
||||
padding-bottom: 90rpx;
|
||||
}
|
||||
|
||||
.btns .t-button {
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.t-upload .t-grid__content .t-grid-item {
|
||||
width: auto !important;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue