123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- // pages/albumEdit/albumEdit.js
- // import {
- // baseUrl
- // } from '../api/request'
- const baseUrl = "https://www.cqna.gov.cn/data/"
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- // 基础地址
- baseUrl: baseUrl,
- // 默认归属日期
- vestingDate: '',
- // 默认作品年代
- pictureType: '',
- // 作品年代
- array: ['解放前', '解放后-80年代', '80年代-新世纪', '新世纪-千禧年'],
- // 图片
- img: ''
- },
- // 提交
- formSubmit(e) {
- if (e.detail.value.uploaderPhone == '') {
- wx.showToast({
- title: "作者电话不能为空",
- icon: "none",
- duration: 1500
- })
- } else if (!(/^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/.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 (e.detail.value.pictureDescription == '') {
- wx.showToast({
- title: "作品描述不能为空",
- icon: "none",
- duration: 1500
- })
- } else if (this.data.img == '') {
- 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) {
- let data = JSON.parse(res.data);
- if (data.result) {
- wx.showToast({
- title: "投稿成功",
- icon: "success",
- duration: 1500,
- success: res => {
- setTimeout(() => {
- wx.navigateBack({
- delta: 1
- });
- }, 1500)
- }
- })
- } else {
- wx.showToast({
- title: "投稿失败",
- icon: "none",
- duration: 2000
- })
- }
- },
- 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,
- mediaType: ['image'],
- sizeType: ["original", "compressed"],
- sourceType: ["album"],
- success: function (res) {
- var tempFilePaths = res.tempFiles[0];
- if (tempFilePaths.size > 1024 * 1024 * 5) {
- wx.showToast({
- title: "图片过大",
- icon: "none",
- duration: 1500
- })
- } else {
- that.setData({
- img: tempFilePaths.tempFilePath
- })
- }
- }
- })
- },
- // 日期切换
- bindDateChange(e) {
- // console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- vestingDate: e.detail.value
- })
- },
- // 作品年代切换
- bindPickerChange: function (e) {
- // console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- 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
- })
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- return {
- title: '我要投稿'
- };
- }
- })
|