newsaddvideo.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <view class="check">
  3. <uni-forms ref="form" :model="datainfo">
  4. <view class="cbox">
  5. <view class="chmain">
  6. <uni-forms-item label="发布时间" name="publishTime">
  7. <picker mode="date" :disabled="isdisabled" @change='bindDateChangeb'>
  8. <view class="flexc">
  9. <view class="flex1 txr f13" :class="datainfo.publishTime?'co27':'coa'">{{datainfo.publishTime||"请选择发布时间"}}</view>
  10. <view class="rimg"><image :src="rimg"></image></view>
  11. </view>
  12. </picker>
  13. </uni-forms-item>
  14. <uni-forms-item label="是否启用" name="status">
  15. <view class="flexc" @click="getChangeFn">
  16. <view class="flex1"></view>
  17. <image :src="check" v-if="datainfo.status=='0'" class="checkimg"></image>
  18. <image :src="ncheck" v-else class="checkimg"></image>
  19. </view>
  20. </uni-forms-item>
  21. </view>
  22. </view>
  23. <view class="cbox">
  24. <view class="chmain">
  25. <uni-forms-item label-width='0' name="manualTitle">
  26. <uni-easyinput :disabled="isdisabled" type="textarea" autoHeight v-model="datainfo.manualTitle" :inputBorder='false' placeholder="输入标题" />
  27. </uni-forms-item>
  28. <view class="addbox">
  29. <!-- <lsj-upload ref="lsjUpload" childId="upload1" :width="width" :height="height" :option="option" :size="size" :formats="formats" :debug="debug" :instantly="instantly" bigType=''
  30. @progress="" @uploadEnd="onuploadEnd" >
  31. <view class="flexdcc" :style="{width: width,height: height}">
  32. <image :src="video"></image>
  33. <view>添加视频</view>
  34. </view>
  35. </lsj-upload> -->
  36. <view class="flexdcc" @click="getchooseVideo" :style="{width: width,height: height}">
  37. <image :src="video"></image>
  38. <view>添加视频</view>
  39. </view>
  40. </view>
  41. <view class="flexcw" v-if="datainfo.videoUrl">
  42. <view class="imgs">
  43. <video class="img" id="myVideo" :src="baseUrl+datainfo.videoUrl"
  44. @error="videoErrorCallback" controls></video>
  45. <cover-image :src="del" class="del" @click.stop="getDelFn"></cover-image>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </uni-forms>
  51. <view class="rfbtn" @click="getEditFn" v-if="isdisabled">修改</view>
  52. <view class="rfbtn" @click="getSubmit" v-else>发布</view>
  53. <loading></loading>
  54. </view>
  55. </template>
  56. <script>
  57. import config from '@/config'
  58. const baseUrl = config.baseUrl
  59. const Clientid = config.Clientid
  60. import { getToken } from '@/utils/auth'
  61. import {checkPermi,checkRole} from "@/utils/permission"; // 权限判断函数
  62. import {manualAdd,manualPut,manualDet} from "@/api/work/manage.js"
  63. import {uploadVideo} from '@/utils/common.js'
  64. export default {
  65. components: {},
  66. data() {
  67. return {
  68. //附件
  69. option: {
  70. // 上传服务器地址,需要替换为你的接口地址
  71. url: baseUrl+'/common/upload', // 该地址非真实路径,需替换为你项目自己的接口地址
  72. // 上传附件的key
  73. name: 'file',
  74. // 根据你接口需求自定义请求头,默认不要写content-type,让浏览器自适配
  75. header: {
  76. // 示例参数可删除
  77. 'Authorization': 'Bearer ' + getToken(),
  78. 'Clientid': Clientid,
  79. },
  80. // 根据你接口需求自定义body参数
  81. formData: {
  82. }
  83. },
  84. // 选择文件后是否立即自动上传,true=选择后立即上传
  85. instantly: true,
  86. // 必传宽高且宽高应与slot宽高保持一致
  87. width: '642rpx',
  88. height: '190rpx',
  89. // 限制允许上传的格式,空串=不限制,默认为空
  90. formats: 'MP4',
  91. // 文件上传大小限制
  92. size: 100,
  93. // 文件数量限制 默认10
  94. count: 5,
  95. // 文件回显列表
  96. files: new Map(),
  97. // 微信小程序Map对象for循环不显示,所以转成普通数组,不要问为什么,我也不知道
  98. wxFiles: [],
  99. // 是否打印日志
  100. debug: false,
  101. filelist:[],
  102. rimg: require('@/people/static/people/rimg.png'),
  103. video: require('@/manage/static/community/video.png'),
  104. del: require('@/car/static/car/del.png'),
  105. baseUrl: config.baseUrl,
  106. checkflag:true,
  107. check: require('@/people/static/people/check.png'),
  108. ncheck: require('@/people/static/people/ncheck.png'),
  109. datainfo: {
  110. // "manualId":"员工培训手册ID",
  111. "manualTitle":"",//员工培训手册标题
  112. "manualType":"2",//员工培训手册类型(1:图片 2:视频)
  113. "manualContent":"",//员工培训手册内容
  114. "status":"0",//员工培训手册状态(0正常 1关闭)
  115. "publishTime":"",//发布时间
  116. "videoUrl":"",//视频地址URL
  117. // "coverImage":"封面图片",
  118. // "author":"作者",
  119. // "source":"来源",
  120. // "viewCount":"浏览次数",
  121. // "isTop":"是否置顶:Y(置顶)、N(不置顶)"
  122. },
  123. id:'',
  124. ptype:"add",
  125. isdisabled:false,
  126. editinfo:'',
  127. videofile:[],
  128. }
  129. },
  130. onLoad: function(e) {
  131. if(e.id){
  132. this.id=e.id;
  133. this.ptype='edit';
  134. // this.isdisabled=true;
  135. this.getDetailFn()
  136. }else{
  137. this.datainfo.publishTime=this.time()
  138. }
  139. },
  140. methods: {
  141. checkPermi,
  142. checkRole,
  143. time(){
  144. var date = new Date();
  145. var y = date.getFullYear();
  146. var m = date.getMonth() + 1;
  147. var d = date.getDate();
  148. var h = date.getHours();
  149. var min = date.getMinutes();
  150. var s = date.getSeconds();
  151. var yearStr = y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d)
  152. // var timeStr = (h < 10 ? ('0' + h) : h) + ':' + (min < 10 ? ('0' + min) : min) + ':' + (s < 10 ? (
  153. // '0' + s) : s);
  154. // var kaTime = yearStr + ' ' + timeStr;
  155. return yearStr
  156. },
  157. bindDateChangeb(e){
  158. var val=e.detail.value;
  159. this.datainfo.publishTime=val;
  160. },
  161. getEditFn(){
  162. this.isdisabled=false;
  163. },
  164. getDelFn(idx){
  165. var that=this;
  166. uni.showModal({
  167. title: '确认删除',
  168. content: "是否确认删除",
  169. cancelText: '取消',
  170. confirmText: '确认',
  171. success: function(res) {
  172. if (res.confirm) {
  173. that.datainfo.videoUrl='';
  174. } else if (res.cancel) {
  175. }
  176. }
  177. });
  178. },
  179. getChangeFn(){
  180. if(this.isdisabled){
  181. return
  182. }
  183. console.log(this.datainfo.status)
  184. if(this.datainfo.status=='1'){
  185. this.datainfo.status='2'
  186. }else{
  187. this.datainfo.status='1'
  188. }
  189. },
  190. getchooseVideo(e){
  191. var that=this;
  192. uni.chooseVideo({
  193. sourceType: ['camera', 'album'],
  194. success: function (res) {
  195. let img= res.tempFilePath;
  196. var fuwufile = [];
  197. uploadVideo('/common/upload',img,fuwufile,function(rs){
  198. var resurl=rs[0];
  199. that.datainfo.videoUrl=resurl.fileName
  200. })
  201. }
  202. });
  203. },
  204. // 上传
  205. onuploadEnd(item,fileVal,bigType) {
  206. var newobj={}
  207. var responseText=JSON.parse(item.responseText)
  208. if(responseText.code==200){
  209. this.datainfo.videoUrl=responseText.data.fileName
  210. // newobj.name=responseText.newFileName;
  211. // newobj.oldName=responseText.originalFilename;
  212. // newobj.url=responseText.fileName;
  213. // newobj.type=fileVal;
  214. // newobj.bigType=bigType;
  215. // newobj.suggestionId=this.suggestionId;
  216. // this.filelist.push(newobj)
  217. }else{
  218. this.$toast(responseText.msg)
  219. }
  220. },
  221. getDetailFn(){
  222. var that=this;
  223. manualDet(this.id).then(res=>{
  224. if(res.code==200){
  225. this.datainfo=res.data;
  226. }
  227. })
  228. },
  229. getSubmit(){
  230. var that=this;
  231. this.$refs.form.validate().then(res => {
  232. var params=JSON.parse(JSON.stringify(this.datainfo))
  233. if(!params.publishTime){
  234. this.$toast('请选择发布时间')
  235. return
  236. }
  237. if(!params.manualTitle){
  238. this.$toast('请输入标题')
  239. return
  240. }
  241. if(!params.videoUrl){
  242. this.$toast('请上传视频')
  243. return
  244. }
  245. if(this.ptype=='add'){
  246. manualAdd(params).then(res=>{
  247. if(res.code==200){
  248. this.$toast("新增成功")
  249. setTimeout(function(){
  250. uni.$emit("newsygList")
  251. uni.navigateBack({
  252. delta:1
  253. })
  254. },1500)
  255. }
  256. })
  257. }else{
  258. manualPut(params).then(res=>{
  259. if(res.code==200){
  260. this.$toast("修改成功")
  261. setTimeout(function(){
  262. uni.$emit("newsygList")
  263. uni.navigateBack({
  264. delta:1
  265. })
  266. },1500)
  267. }
  268. })
  269. }
  270. })
  271. },
  272. }
  273. }
  274. </script>
  275. <style>
  276. page{background: #F3F3F0;}
  277. </style>
  278. <style lang="scss" scoped>
  279. .check /deep/ .uni-forms-item{min-height: 106rpx;box-sizing: border-box;display: flex;align-items: center;margin-bottom: 0;border-bottom: 2rpx solid #E6E6E6;padding:10rpx 0;}
  280. .check .cbox /deep/ .uni-forms-item:last-child{border: none;}
  281. .check /deep/ .uni-forms-item__label{font-weight: bold;font-size: 26rpx;color: #222327;flex: 0 0 auto;width: auto !important;}
  282. .check /deep/ .uni-easyinput{flex: 1;text-align: left;font-size: 26rpx;color: #222327;}
  283. .check /deep/ .uni-easyinput__content-textarea{min-height: 40rpx;font-size: 26rpx;}
  284. .check /deep/ .uni-easyinput__placeholder-class{font-size: 26rpx;color: #AAAAAA;}
  285. .check /deep/ .uni-easyinput__content-input{padding-left: 0 !important;}
  286. .check /deep/ .uni-input-input{font-size: 26rpx;}
  287. .check /deep/ .uni-textarea-textarea{font-size: 26rpx;}
  288. .check /deep/ .is-disabled{color: #222327;background-color: #ffffff !important;}
  289. .check /deep/ .uni-data-checklist .checklist-group .checklist-box{margin:10rpx 8rpx 10rpx 16rpx;}
  290. .check /deep/ .uni-data-checklist{flex: 0 0 auto;}
  291. .check{min-height: 100vh;padding: 20rpx 18rpx 110rpx;box-sizing: border-box;}
  292. .cbox{background: #FFFFFF;border-radius: 20rpx;flex: 1;margin-bottom: 24rpx;
  293. .chmain{
  294. padding: 0 32rpx 10rpx;box-sizing: border-box;
  295. .rimg{width: 16rpx;height: 28rpx;flex: 0 0 auto;margin-left: 20rpx;
  296. image{width: 100%;height: 100%;}
  297. }
  298. .checkimg{width: 80rpx;height: 40rpx;margin-right: 8rpx;}
  299. }
  300. }
  301. .addbox{height: 190rpx;background: #FFFFFF;border-radius: 10rpx;border: 2rpx dashed #A7A7A7;margin: 48rpx 0 56rpx;
  302. image{width: 54rpx;height: 46rpx;margin-bottom: 16rpx;}
  303. view{font-weight: bold;font-size: 26rpx;color: #272727;}
  304. }
  305. .imgs{
  306. width: 310rpx;height: 186rpx;position: relative;margin: 0 10rpx 10rpx 0;
  307. .img{width: 100%;height: 100%;}
  308. .del{width: 24rpx;height: 24rpx;position: absolute;right: 0;top: 0;z-index: 2;}
  309. }
  310. </style>