Selaa lähdekoodia

富文本,上传视频修改

zouling 2 viikkoa sitten
vanhempi
commit
f6238d2f5c

+ 69 - 46
property_ui/manage/pages/community/newsadd.vue

@@ -230,55 +230,78 @@
 					}
 				})
 			},
-			getSubmit(){
-				var that=this;
-				this.$refs.form.validate().then(res => {
-					var params=JSON.parse(JSON.stringify(this.datainfo))
-					if(!params.publishTime){
-						this.$toast('请选择发布时间')
-						return
-					}
-					if(!params.manualTitle){
-						this.$toast('请输入标题')
-						return
+			getEditorContent(){
+				return new Promise((resolve, reject) => {
+					if (this.editorCtx) {
+					    var infoContent='';
+					    this.editorCtx.getContents({
+					        success: function(data) {
+					    		var s=data.html;
+					            infoContent=s.replace(/\<img src="(http?:\/\/)([^\/]+)(:\d+)?/g,'<img src="');
+					            infoContent=infoContent.replace(/\<img src="(https?:\/\/)([^\/]+)(:\d+)?/g,'<img src="');
+					    		 resolve(infoContent)
+					        },
+					    	fail: (err) => {
+					    	  reject(err)
+					    	}
+					    })
+					} else {
+					  reject('编辑器未初始化')
 					}
-					var infoContent=''
-					this.editorCtx.getContents({
-					    success: function(data) {
-							var s=data.html;
-					        infoContent=s.replace(/\<img src="(http?:\/\/)([^\/]+)(:\d+)?/g,'<img src="');
-					        infoContent=infoContent.replace(/\<img src="(https?:\/\/)([^\/]+)(:\d+)?/g,'<img src="');
-					    }  
-					}) 
-					params.manualContent=infoContent;
-					if(this.ptype=='add'){
-						manualAdd(params).then(res=>{
-							if(res.code==200){
-								this.$toast("新增成功")
-								setTimeout(function(){
-									uni.$emit("newsygList")
-									uni.navigateBack({
-										delta:1
-									})
-								},1500)
-							}
-						})
-					}else{
-						manualPut(params).then(res=>{
-							if(res.code==200){
-								this.$toast("修改成功")
-								setTimeout(function(){
-									uni.$emit("newsygList")
-									uni.navigateBack({
-										delta:1
-									})
-								},1500)
-							}
-						})
-					}
-					
 				})
 			},
+			async getSubmit() {
+				try {
+					var that=this;
+					const content = await this.getEditorContent()
+					this.$refs.form.validate().then(res => {
+						var params=JSON.parse(JSON.stringify(this.datainfo))
+						if(!params.publishTime){
+							this.$toast('请选择发布时间')
+							return
+						}
+						if(!params.manualTitle){
+							this.$toast('请输入标题')
+							return
+						} 
+						params.manualContent=content;
+						if(this.ptype=='add'){
+							manualAdd(params).then(res=>{
+								if(res.code==200){
+									this.$toast("新增成功")
+									setTimeout(function(){
+										uni.$emit("newsygList")
+										uni.navigateBack({
+											delta:1
+										})
+									},1500)
+								}
+							})
+						}else{
+							manualPut(params).then(res=>{
+								if(res.code==200){
+									this.$toast("修改成功")
+									setTimeout(function(){
+										uni.$emit("newsygList")
+										uni.navigateBack({
+											delta:1
+										})
+									},1500)
+								}
+							})
+						}
+						
+					})
+				} catch (error) {
+				  console.error('提交失败:', error)
+				  uni.showToast({
+				    title: error.message || '提交失败',
+				    icon: 'none'
+				  })
+				} finally {
+				  
+				}
+			},
 			//解析富文本方法
 			formatRichText(html) {
 					let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {

+ 73 - 50
property_ui/manage/pages/community/newsadddj.vue

@@ -265,59 +265,82 @@
 					}
 				})
 			},
-			getSubmit(){
-				var that=this;
-				this.$refs.form.validate().then(res => {
-					var params=JSON.parse(JSON.stringify(this.datainfo))
-					if(!params.partyType){
-						this.$toast('请选择文章类型')
-						return
-					}
-					if(!params.publishTime){
-						this.$toast('请选择发布时间')
-						return
-					}
-					if(!params.partyTitle){
-						this.$toast('请输入标题')
-						return
-					}
-					var infoContent=''
-					this.editorCtx.getContents({
-					    success: function(data) {
-							var s=data.html;
-					        infoContent=s.replace(/\<img src="(http?:\/\/)([^\/]+)(:\d+)?/g,'<img src="');
-					        infoContent=infoContent.replace(/\<img src="(https?:\/\/)([^\/]+)(:\d+)?/g,'<img src="');
-					    }  
-					}) 
-					params.partyContent=infoContent;
-					if(this.ptype=='add'){
-						partyNewsAdd(params).then(res=>{
-							if(res.code==200){
-								this.$toast("新增成功")
-								setTimeout(function(){
-									uni.$emit("partyNewsList")
-									uni.navigateBack({
-										delta:1
-									})
-								},1500)
-							}
-						})
-					}else{
-						partyNewsPut(params).then(res=>{
-							if(res.code==200){
-								this.$toast("修改成功")
-								setTimeout(function(){
-									uni.$emit("partyNewsList")
-									uni.navigateBack({
-										delta:1
-									})
-								},1500)
-							}
-						})
+			getEditorContent(){
+				return new Promise((resolve, reject) => {
+					if (this.editorCtx) {
+					    var infoContent='';
+					    this.editorCtx.getContents({
+					        success: function(data) {
+					    		var s=data.html;
+					            infoContent=s.replace(/\<img src="(http?:\/\/)([^\/]+)(:\d+)?/g,'<img src="');
+					            infoContent=infoContent.replace(/\<img src="(https?:\/\/)([^\/]+)(:\d+)?/g,'<img src="');
+					    		 resolve(infoContent)
+					        },
+					    	fail: (err) => {
+					    	  reject(err)
+					    	}
+					    })
+					} else {
+					  reject('编辑器未初始化')
 					}
-					
 				})
 			},
+			async getSubmit() {
+				try {
+					var that=this;
+					const content = await this.getEditorContent()
+					this.$refs.form.validate().then(res => {
+						var params=JSON.parse(JSON.stringify(this.datainfo))
+						if(!params.partyType){
+							this.$toast('请选择文章类型')
+							return
+						}
+						if(!params.publishTime){
+							this.$toast('请选择发布时间')
+							return
+						}
+						if(!params.partyTitle){
+							this.$toast('请输入标题')
+							return
+						}
+						params.partyContent=content;
+						if(this.ptype=='add'){
+							partyNewsAdd(params).then(res=>{
+								if(res.code==200){
+									this.$toast("新增成功")
+									setTimeout(function(){
+										uni.$emit("partyNewsList")
+										uni.navigateBack({
+											delta:1
+										})
+									},1500)
+								}
+							})
+						}else{
+							partyNewsPut(params).then(res=>{
+								if(res.code==200){
+									this.$toast("修改成功")
+									setTimeout(function(){
+										uni.$emit("partyNewsList")
+										uni.navigateBack({
+											delta:1
+										})
+									},1500)
+								}
+							})
+						}
+						
+					})
+				} catch (error) {
+				  console.error('提交失败:', error)
+				  uni.showToast({
+				    title: error.message || '提交失败',
+				    icon: 'none'
+				  })
+				} finally {
+				  
+				}
+			},
 			//解析富文本方法
 			formatRichText(html) {
 					let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {

+ 73 - 50
property_ui/manage/pages/community/newsaddsq.vue

@@ -266,59 +266,82 @@
 					}
 				})
 			},
-			getSubmit(){
-				var that=this;
-				this.$refs.form.validate().then(res => {
-					var params=JSON.parse(JSON.stringify(this.datainfo))
-					if(!params.communityType){
-						this.$toast('请选择资讯类型')
-						return
-					}
-					if(!params.publishTime){
-						this.$toast('请选择发布时间')
-						return
-					}
-					if(!params.communityTitle){
-						this.$toast('请输入标题')
-						return
+			getEditorContent(){
+				return new Promise((resolve, reject) => {
+					if (this.editorCtx) {
+					    var infoContent='';
+					    this.editorCtx.getContents({
+					        success: function(data) {
+					    		var s=data.html;
+					            infoContent=s.replace(/\<img src="(http?:\/\/)([^\/]+)(:\d+)?/g,'<img src="');
+					            infoContent=infoContent.replace(/\<img src="(https?:\/\/)([^\/]+)(:\d+)?/g,'<img src="');
+					    		 resolve(infoContent)
+					        },
+					    	fail: (err) => {
+					    	  reject(err)
+					    	}
+					    })
+					} else {
+					  reject('编辑器未初始化')
 					}
-					var infoContent=''
-					this.editorCtx.getContents({
-					    success: function(data) {
-							var s=data.html;
-					        infoContent=s.replace(/\<img src="(http?:\/\/)([^\/]+)(:\d+)?/g,'<img src="');
-					        infoContent=infoContent.replace(/\<img src="(https?:\/\/)([^\/]+)(:\d+)?/g,'<img src="');
-					    }  
-					}) 
-					params.communityContent=infoContent;
-					if(this.ptype=='add'){
-						newsAdd(params).then(res=>{
-							if(res.code==200){
-								this.$toast("新增成功")
-								setTimeout(function(){
-									uni.$emit("newsList")
-									uni.navigateBack({
-										delta:1
-									})
-								},1500)
-							}
-						})
-					}else{
-						newsPut(params).then(res=>{
-							if(res.code==200){
-								this.$toast("修改成功")
-								setTimeout(function(){
-									uni.$emit("newsList")
-									uni.navigateBack({
-										delta:1
-									})
-								},1500)
-							}
-						})
-					}
-					
 				})
 			},
+			async getSubmit() {
+				try {
+					var that=this;
+					const content = await this.getEditorContent()
+					this.$refs.form.validate().then(res => {
+						var params=JSON.parse(JSON.stringify(this.datainfo))
+						if(!params.communityType){
+							this.$toast('请选择资讯类型')
+							return
+						}
+						if(!params.publishTime){
+							this.$toast('请选择发布时间')
+							return
+						}
+						if(!params.communityTitle){
+							this.$toast('请输入标题')
+							return
+						}
+						params.communityContent=content;
+						if(this.ptype=='add'){
+							newsAdd(params).then(res=>{
+								if(res.code==200){
+									this.$toast("新增成功")
+									setTimeout(function(){
+										uni.$emit("newsList")
+										uni.navigateBack({
+											delta:1
+										})
+									},1500)
+								}
+							})
+						}else{
+							newsPut(params).then(res=>{
+								if(res.code==200){
+									this.$toast("修改成功")
+									setTimeout(function(){
+										uni.$emit("newsList")
+										uni.navigateBack({
+											delta:1
+										})
+									},1500)
+								}
+							})
+						}
+						
+					})
+				} catch (error) {
+				  console.error('提交失败:', error)
+				  uni.showToast({
+				    title: error.message || '提交失败',
+				    icon: 'none'
+				  })
+				} finally {
+					
+				}	
+			},
 			//解析富文本方法
 			formatRichText(html) {
 					let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {

+ 22 - 5
property_ui/manage/pages/community/newsaddvideo.vue

@@ -26,14 +26,17 @@
 						<uni-easyinput :disabled="isdisabled" type="textarea" autoHeight v-model="datainfo.manualTitle" :inputBorder='false' placeholder="输入标题" />
 					</uni-forms-item>
 					<view class="addbox">
-						<lsj-upload ref="lsjUpload" childId="upload1"  :width="width" :height="height" :option="option" :size="size" :formats="formats" :debug="debug" :instantly="instantly" bigType=''
+						<!-- <lsj-upload ref="lsjUpload" childId="upload1"  :width="width" :height="height" :option="option" :size="size" :formats="formats" :debug="debug" :instantly="instantly" bigType=''
 							    @progress="" @uploadEnd="onuploadEnd" >
-								<!-- fileName="123" fileVal='dbxmhfhgb' bigType="c" -->
 							<view class="flexdcc" :style="{width: width,height: height}">
 								<image :src="video"></image>
 								<view>添加视频</view>
 							</view>
-						</lsj-upload>
+						</lsj-upload> -->
+						<view class="flexdcc" @click="getchooseVideo" :style="{width: width,height: height}">
+							<image :src="video"></image>
+							<view>添加视频</view>
+						</view>
 					</view>
 					
 					
@@ -41,7 +44,7 @@
 						<view class="imgs">
 							<video class="img" id="myVideo" :src="baseUrl+datainfo.videoUrl"
 							      @error="videoErrorCallback"  controls></video>
-							<image :src="del" class="del" @click.stop="getDelFn"></image>
+							<cover-image :src="del" class="del" @click.stop="getDelFn"></cover-image>
 						</view>
 					</view>
 				</view>
@@ -60,7 +63,7 @@
 	import { getToken } from '@/utils/auth'
 	import {checkPermi,checkRole} from "@/utils/permission"; // 权限判断函数
 	import {manualAdd,manualPut,manualDet} from "@/api/work/manage.js"
-	import {uploadIdentify} from '@/utils/common.js'
+	import {uploadVideo} from '@/utils/common.js'
 	export default {
 		components: {},
 		data() {
@@ -187,6 +190,20 @@
 					this.datainfo.status='1'
 				}
 			},
+			getchooseVideo(e){
+				var that=this;
+				uni.chooseVideo({
+					sourceType: ['camera', 'album'],
+				success: function (res) {
+					let img= res.tempFilePath;
+					var fuwufile = [];
+					uploadVideo('/common/upload',img,fuwufile,function(rs){
+						var resurl=rs[0];
+						that.datainfo.videoUrl=resurl.fileName
+					})
+				}
+			});
+			},
 			// 上传
 			onuploadEnd(item,fileVal,bigType) {
 				var newobj={}

+ 1 - 1
property_ui/manifest.json

@@ -55,7 +55,7 @@
             "sdkConfigs" : {
                 "share" : {
                     "weixin" : {
-                        "appid" : "wx47d585d225f26459",
+                        "appid" : "wx5510cc9c44b459f1",
                         "UniversalLinks" : ""
                     }
                 },

+ 69 - 0
property_ui/utils/common.js

@@ -116,6 +116,75 @@ export function tansParams(params) {
   }
   return result
 }
+//上传视频
+export function uploadVideo(api, filePaths, files, callback) {
+	const isToken = (config.headers || {}).isToken === false
+	config.header = config.header || {}
+	if (getToken() && !isToken) {
+	  config.header['Authorization'] = 'Bearer ' + getToken()
+	  config.header['clientid']=clientid;
+	}
+	// get请求映射params参数
+	if (config.params) {
+	  let url = config.url + '?' + tansParams(config.params)
+	  url = url.slice(0, -1)
+	  config.url = url
+	}
+	
+	uni.showLoading({
+		title: '上传中'
+	})
+	var failfile = [];
+	uni.uploadFile({
+		timeout: config.timeout || timeout,
+		url: baseUrl + api, //仅为示例,非真实的接口地址
+		filePath: filePaths,
+		name: 'file',
+		header: config.header,
+		formData: config.formData,
+		success: function(resp) {
+			uni.hideLoading();
+			let result = JSON.parse(resp.data)
+			const code = result.code || 200
+			const msg = errorCode[code] || result.msg || errorCode['default']
+			if (result.code == 200) {
+				files[0] = result.data;
+			} else if(result.code==401) {
+				showConfirm("登录状态已过期,您可以继续留在该页面,或者重新登录?").then(res => {
+				  if (res.confirm) {
+				    store.dispatch('LogOut').then(res => {
+				      uni.reLaunch({ url: '/pages/login/login' })
+				    })
+				  }
+				})
+				callback('无效的会话,或者会话已过期,请重新登录。');
+			}else{
+				failfile = failfile.concat(filePaths[i])
+				
+			}
+		},
+		fail: function(res) {
+			uni.hideLoading();
+			failfile = failfile.concat(filePaths[i])
+		},
+		complete: function(rsp) {
+			// console.log(rsp, filePaths[i])
+			uni.hideLoading();
+			// i++;
+			// if (i == length) {
+			// 	uni.showToast({
+			// 		title: '上传成功',
+			// 		icon: 'none',
+			// 		duration: 2000
+			// 	});
+				callback(files);
+			// } else { //递归调用upload函数
+			// 	uploadIdentify(api, filePaths, successUp, failUp, i, length, files, callback);
+			// }
+		}
+	});
+
+}
 //上传图片(本地地址识别一张)
 export function uploadIdentify(api, filePaths, successUp, failUp, i, length, files, callback) {
 	const isToken = (config.headers || {}).isToken === false