Browse Source

对接小程序印象南岸我要投稿

wrh 2 years ago
parent
commit
2eca4f1e6d

+ 135 - 41
nngkxxdp/src/main/resources/static/nnzwminiapp/pages/albumEdit/albumEdit.js

@@ -1,14 +1,19 @@
 // pages/albumEdit/albumEdit.js
+import {
+	baseUrl
+} from '../api/request'
 Page({
 
 	/**
 	 * 页面的初始数据
 	 */
 	data: {
+		// 基础地址
+		baseUrl: baseUrl,
 		// 默认归属日期
-		date: '',
+		vestingDate: '',
 		// 默认作品年代
-		index: '',
+		pictureType: '',
 		// 作品年代
 		array: ['解放前', '解放后-80年代', '80年代-新世纪', '新世纪-千禧年'],
 		// 图片
@@ -16,49 +21,106 @@ Page({
 	},
 	// 提交
 	formSubmit(e) {
-		console.log('form发生了submit事件,携带数据为:', e.detail.value)
+		if (e.detail.value.uploaderPhone == '') {
+			wx.showToast({
+				title: "作者电话不能为空",
+				icon: "none",
+				duration: 1500
+			})
+		} else if (!(/^1[34578]\d{9}$/.test(e.detail.value.uploaderPhone))) {
+			wx.showToast({
+				title: "请输入正确的电话号码",
+				icon: "none",
+				duration: 1500
+			})
+		} else if (e.detail.value.pictureTitle == '') {
+			wx.showToast({
+				title: "作品名称不能为空",
+				icon: "none",
+				duration: 1500
+			})
+		} else if (e.detail.value.pictureAuthor == '') {
+			wx.showToast({
+				title: "作品作者不能为空",
+				icon: "none",
+				duration: 1500
+			})
+		} else if (e.detail.value.vestingDate == '') {
+			wx.showToast({
+				title: "归属日期不能为空",
+				icon: "none",
+				duration: 1500
+			})
+		} else if (e.detail.value.pictureType == '') {
+			wx.showToast({
+				title: "作品年代不能为空",
+				icon: "none",
+				duration: 1500
+			})
+		} else if (this.data.img == '') {
+			wx.showToast({
+				title: "我的作品不能为空",
+				icon: "none",
+				duration: 1500
+			})
+		} else if (e.detail.value.pictureDescription == '') {
+			wx.showToast({
+				title: "作品描述不能为空",
+				icon: "none",
+				duration: 1500
+			})
+		} else {
+			e.detail.value.isAnonymous = true ? 1 : 0;
+			e.detail.value.isPublic = true ? 0 : 1;
+			wx.uploadFile({
+				url: this.data.baseUrl + '/yxna/uploadDocumet',
+				filePath: this.data.img,
+				name: "file",
+				header: {
+					"content-type": "multipart/form-data"
+				},
+				formData: e.detail.value,
+				success: function (res) {
+					if (res.statusCode == 200) {
+						wx.showToast({
+							title: "投稿成功",
+							icon: "success",
+							duration: 1500
+						})
+					}
+				},
+				fail: function (err) {
+					wx.showToast({
+						title: "投稿失败",
+						icon: "none",
+						duration: 2000
+					})
+				},
+				complete: function (result) {
+					console.log(result.errMsg)
+				}
+			})
+		}
 	},
 	// 上传图片
 	bindUpload: function (e) {
 		var that = this
 		wx.chooseMedia({
-			count: 1, // 默认3
-			sizeType: ["original", "compressed"], // 可以指定是原图还是压缩图,默认二者都有
-			sourceType: ["album", "camera"], // 可以指定来源是相册还是相机,默认二者都有
+			count: 1,
+			mediaType: ['image'],
+			sizeType: ["original", "compressed"],
+			sourceType: ["album", "camera"],
 			success: function (res) {
-				// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
-				var tempFilePaths = res.tempFilePaths
-				for (var i = 0; i < tempFilePaths.length; i++) {
-					wx.uploadFile({
-						url: 'https://graph.baidu.com/upload',
-						filePath: tempFilePaths[i],
-						name: "file",
-						header: {
-							"content-type": "multipart/form-data"
-						},
-						success: function (res) {
-							if (res.statusCode == 200) {
-								wx.showToast({
-									title: "上传成功",
-									icon: "none",
-									duration: 1500
-								})
-								that.data.img.push(JSON.parse(res.data).data)
-								that.setData({
-									img: that.data.imgs
-								})
-							}
-						},
-						fail: function (err) {
-							wx.showToast({
-								title: "上传失败",
-								icon: "none",
-								duration: 2000
-							})
-						},
-						complete: function (result) {
-							console.log(result.errMsg)
-						}
+				var tempFilePaths = res.tempFiles[0];
+				if (tempFilePaths.size > 1024 * 1024 * 5) {
+					wx.showToast({
+						title: "图片过大",
+						icon: "none",
+						duration: 1500
+					})
+				} else {
+					that.setData({
+						img: tempFilePaths.tempFilePath
 					})
 				}
 			}
@@ -68,16 +130,48 @@ Page({
 	bindDateChange(e) {
 		console.log('picker发送选择改变,携带值为', e.detail.value)
 		this.setData({
-			date: e.detail.value
+			vestingDate: e.detail.value
 		})
 	},
 	// 作品年代切换
 	bindPickerChange: function (e) {
 		console.log('picker发送选择改变,携带值为', e.detail.value)
 		this.setData({
-			index: e.detail.value
+			pictureType: e.detail.value
 		})
 	},
+	// 切换作者电话是否公开
+	publicChange(e) {
+		if (e.detail.value) {
+			wx.showToast({
+				title: "切换为公开",
+				icon: "none",
+				duration: 1500
+			})
+		} else {
+			wx.showToast({
+				title: "切换为不公开",
+				icon: "none",
+				duration: 1500
+			})
+		}
+	},
+	// 切换作者是否匿名
+	anonymousChange(e) {
+		if (e.detail.value) {
+			wx.showToast({
+				title: "切换为不匿名",
+				icon: "none",
+				duration: 1500
+			})
+		} else {
+			wx.showToast({
+				title: "切换为匿名",
+				icon: "none",
+				duration: 1500
+			})
+		}
+	},
 	/**
 	 * 生命周期函数--监听页面加载
 	 */

+ 12 - 13
nngkxxdp/src/main/resources/static/nnzwminiapp/pages/albumEdit/albumEdit.wxml

@@ -7,31 +7,31 @@
 					<view style="color: #A91919;">*</view>
 					<view style="width: 132rpx;">作者电话</view>
 				</view>
-				<input name="phone" style="font-size: 24rpx;line-height: 70rpx;height: 70rpx;width: 100%;" placeholder="请输入电话" />
-				<switch name="switchPhone" style="line-height: 60rpx;" />
+				<input name="uploaderPhone" style="font-size: 24rpx;line-height: 70rpx;height: 70rpx;width: 100%;" type='number' placeholder="请输入电话" maxlength="11" />
+				<switch name="isPublic" bindchange="publicChange" style="line-height: 60rpx;" />
 			</view>
 			<view style="display: flex;border-bottom: 1px solid #DDDDDD;margin: 20rpx 18rpx;">
 				<view style="font-size: 24rpx;display: flex;line-height: 70rpx;height: 70rpx;">
 					<view style="color: #A91919;">*</view>
 					<view style="width: 132rpx;">作品名称</view>
 				</view>
-				<input name="name" style="font-size: 24rpx;line-height: 70rpx;height: 70rpx;width: 100%;" placeholder="请输入作品名称" />
+				<input name="pictureTitle" style="font-size: 24rpx;line-height: 70rpx;height: 70rpx;width: 100%;" placeholder="请输入作品名称" />
 			</view>
 			<view style="display: flex;border-bottom: 1px solid #DDDDDD;margin: 20rpx 18rpx;">
 				<view style="font-size: 24rpx;display: flex;line-height: 70rpx;height: 70rpx;">
 					<view style="color: #A91919;">*</view>
 					<view style="width: 132rpx;">作品作者</view>
 				</view>
-				<input name="author" style="font-size: 24rpx;line-height: 70rpx;height: 70rpx;width: 100%;" placeholder="请输入作品作者" />
-				<switch name="switchAuthor" style="line-height: 60rpx;" />
+				<input name="pictureAuthor" style="font-size: 24rpx;line-height: 70rpx;height: 70rpx;width: 100%;" placeholder="请输入作品作者" />
+				<switch name="isAnonymous" bindchange="anonymousChange" style="line-height: 60rpx;" />
 			</view>
 			<view style="display: flex;border-bottom: 1px solid #DDDDDD;margin: 20rpx 18rpx;">
 				<view style="font-size: 24rpx;display: flex;line-height: 70rpx;height: 70rpx;">
 					<view style="color: #A91919;">*</view>
 					<view style="width: 132rpx;">归属日期</view>
 				</view>
-				<picker name="date" mode="date" value="{{date}}" bindchange="bindDateChange" style="line-height: 70rpx;font-size: 24rpx;">
-					<input style="font-size: 24rpx;line-height: 70rpx;height: 70rpx;width: 100%;" placeholder="请选择归属日期" value="{{date}}" />
+				<picker name="vestingDate" mode="date" value="{{vestingDate}}" bindchange="bindDateChange" style="line-height: 70rpx;font-size: 24rpx;width: 100%;">
+					<input style="font-size: 24rpx;line-height: 70rpx;height: 70rpx;width: 100%;" disabled="true" placeholder="请选择归属日期" value="{{vestingDate}}" />
 				</picker>
 			</view>
 			<view style="display: flex;border-bottom: 1px solid #DDDDDD;margin: 20rpx 18rpx;">
@@ -39,8 +39,8 @@
 					<view style="color: #A91919;">*</view>
 					<view style="width: 132rpx;">作品年代</view>
 				</view>
-				<picker name="age" bindchange="bindPickerChange" value="{{index}}" range="{{array}}" style="line-height: 70rpx;font-size: 24rpx;">
-					<input style="font-size: 24rpx;line-height: 70rpx;height: 70rpx;width: 100%;" placeholder="请选择作品年代" value="{{array[index]}}" />
+				<picker name="pictureType" bindchange="bindPickerChange" value="{{pictureType}}" range="{{array}}" style="line-height: 70rpx;font-size: 24rpx;width: 100%;">
+					<input style="font-size: 24rpx;line-height: 70rpx;height: 70rpx;width: 100%;" disabled="true" placeholder="请选择作品年代" value="{{array[pictureType]}}" />
 				</picker>
 			</view>
 			<view style="display: flex;border-bottom: 1px solid #DDDDDD;margin: 20rpx 18rpx;">
@@ -48,14 +48,13 @@
 					<view style="color: #A91919;">*</view>
 					<view style="width: 132rpx;">我的作品</view>
 				</view>
-				<view>
+				<view style="width: 500rpx;">
 					<view>
 						<button bindtap="bindUpload" style="width: 166rpx;height: 60rpx;background: #004A93;border-radius: 10rpx;color: #FFFFFF;font-size: 24rpx;line-height: 60rpx;margin: 0;">上传</button>
 					</view>
 					<view style="font-size: 24rpx;color: #D2D2D2;">支持jpg. png格式,大小在5M以下</view>
 					<view>
-						<image src="{{imgURl}}{{img}}"></image>
-						<input name="img" style="display: none;" value="{{imgURl}}{{img}}" type="text" />
+						<image style="width: 100%;" src="{{imgURl}}{{img}}" />
 					</view>
 				</view>
 			</view>
@@ -64,7 +63,7 @@
 					<view style="color: #A91919;">*</view>
 					<view style="width: 132rpx;">作品描述</view>
 				</view>
-				<textarea name="detail" style="font-size: 24rpx;padding-top: 20rpx;" bindblur="bindTextAreaBlur" auto-height placeholder="请输入你的作品描述" />
+				<textarea name="pictureDescription" style="font-size: 24rpx;padding-top: 20rpx;" maxlength="200" auto-height placeholder="请输入你的作品描述" />
 			</view>
 		</view>
 		<button formType="submit" style="margin-top: 77rpx;width: 676rpx;height: 80rpx;background: #004A93;border-radius: 10rpx;color: #FFFFFF;font-size: 24rpx;line-height: 80rpx;">确认提交</button>