newsaddvideo.vue 9.0 KB

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