123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- // 引入 QCloud 小程序增强 SDK
- var qcloud = require('../../../../vendor/qcloud-weapp-client-sdk/index');
- // 引入配置
- var config = require('../../../../config');
- // 显示繁忙提示
- var showBusy = text => wx.showToast({
- title: text,
- icon: 'loading',
- duration: 10000
- });
- // 显示成功提示
- var showSuccess = text => {
- wx.hideToast();
- wx.showToast({
- title: text,
- icon: 'success'
- });
- };
- // 显示失败提示
- var showModel = (title, content) => {
- wx.hideToast();
- wx.showModal({
- title,
- content: JSON.stringify(content),
- showCancel: false
- });
- };
- var showMsg = (title, content) => {
- wx.hideToast();
- wx.showModal({
- title,
- content: content,
- showCancel: false
- });
- };
- //获取应用实例
- var app = getApp()
- Page({
- data: {
- "videoSrc":'',
- "busy":false,
- "busy1":false,
- "busy2":false,
- "textarea":false,
- "upload_busy":false
- },
- onLoad: function () {
- console.log('onLoad');
- app.getUserInfo(function(userInfo){
- console.log(userInfo);
- });
- this.chooseVideo();
- },
- onShow: function () {
- console.log('onShow');
- },
- chooseVideo: function() {
- var self = this;
- if(self.data.upload_busy){
- return;
- }
- wx.chooseVideo({
- sourceType: ['album','camera'],
- maxDuration: 60,
- success: function(res) {
- console.log('chooseVideo success, temp path is', res.tempFilePath)
- console.log(res);
- if(res.size>50*1024*1000){
- showMsg('提示信息','视频大小不能大于50M');
- return;
- }
- var videoSrc = res.tempFilePath;
- self.setData({
- 'upload_busy':true,
- 'videoSrc':""
- })
- //上传图片到服务器
- wx.uploadFile({
- url: config.service.uploadUrl,
- filePath: videoSrc,
- name: 'file',
- success: function(res) {
- if(res.statusCode==200){
- var data=JSON.parse(res.data);
- console.log(data);
- if(data.success==true){
- self.setData({
- 'videoSrc':data.file.url,
- 'videoContext':wx.createVideoContext('myVideo')
- })
- showSuccess('上传成功');
- }else{
- showMsg('提示信息','上传失败');
- }
- }else if(res.statusCode==413){
- showMsg('提示信息','上传失败,文件过大');
- }else{
- showMsg('提示信息','上传失败');
- }
- },
- fail: function({errMsg}) {
- console.log('uploadVideo fail, errMsg is', errMsg);
- showMsg('提示信息','上传失败,'+errMsg);
- },
- complete:function(){
- self.setData({
- 'upload_busy':false
- })
- }
- })
- },
- fail: function({errMsg}) {
- console.log('chooseVideo fail, err is', errMsg)
- }
- })
- },
- formSubmit1: function(e) {
- // console.log(e);
-
- var self = this;
- if(self.data.upload_busy||self.data.busy1){
- return;
- }
- if(self.data.videoSrc==""){
- showMsg("提示信息","请先上传视频");
- return;
- }
- var data={};
- if(self.data.videoSrc!=""){
- data.image_url=self.data.videoSrc;
- }
- if(e.detail.formId!='the formId is a mock one'){
- data.form_id=e.detail.formId;
- }
- data.type=3
- data.is_qun=1
- self.setData({
- 'busy1':true
- })
- qcloud.request({
- // 要请求的地址
- url: config.service.messageAddUrl,
- method:"POST",
- data: data,
- success(result) {
- console.log(result);
- if(result.data.success==true){
- showSuccess("成功");
- self.data.videoContext.pause();
- wx.navigateTo({
- url: '/pages/person/video/view/view?hash_key='+result.data.id
- })
- }else{
- showMsg("提示信息","新建消息失败,"+result.data.message);
- }
- },
- fail(error) {
- console.log('request fail', error);
- showMsg("提示信息","新建消息失败");
- },
- complete() {
- self.setData({
- 'busy1':false
- })
- console.log('request complete');
- }
- });
- },
- formSubmit2: function(e) {
- // console.log(e);
-
- var self = this;
- if(self.data.upload_busy||self.data.busy2){
- return;
- }
- if(self.data.videoSrc==""){
- showMsg("提示信息","请先上传视频");
- return;
- }
- var data={};
- if(self.data.videoSrc!=""){
- data.image_url=self.data.videoSrc;
- }
- if(e.detail.formId!='the formId is a mock one'){
- data.form_id=e.detail.formId;
- }
- data.type=3
- data.is_qun=0
- self.setData({
- 'busy2':true
- })
- qcloud.request({
- // 要请求的地址
- url: config.service.messageAddUrl,
- method:"POST",
- data: data,
- success(result) {
- console.log(result);
- if(result.data.success==true){
- showSuccess("成功");
- self.data.videoContext.pause();
- wx.navigateTo({
- url: '/pages/person/video/view/view?hash_key='+result.data.id
- })
- }else{
- showMsg("提示信息","新建消息失败,"+result.data.message);
- }
- },
- fail(error) {
- console.log('request fail', error);
- showMsg("提示信息","新建消息失败");
- },
- complete() {
- self.setData({
- 'busy2':false
- })
- console.log('request complete');
- }
- });
- }
- })
|