add_source.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. {extend name="public/container"}
  2. {block name='head_top'}
  3. <link rel="stylesheet" href="//g.alicdn.com/de/prismplayer/2.9.21/skins/default/aliplayer-min.css">
  4. <style>
  5. .layui-form-item .special-label{
  6. width: 50px;
  7. float: left;
  8. height: 30px;
  9. line-height: 38px;
  10. margin-left: 10px;
  11. margin-top: 5px;
  12. border-radius: 5px;
  13. background-color: #0092DC;
  14. text-align: center;
  15. }
  16. .layui-form-item .special-label i{
  17. display: inline-block;
  18. width: 18px;
  19. height: 18px;
  20. font-size: 18px;
  21. color: #fff;
  22. }
  23. .layui-form-item .label-box{
  24. border: 1px solid;
  25. border-radius: 10px;
  26. position: relative;
  27. padding: 10px;
  28. height: 30px;
  29. color: #fff;
  30. background-color: #393D49;
  31. text-align: center;
  32. cursor: pointer;
  33. display: inline-block;
  34. line-height: 10px;
  35. }
  36. .layui-form-item .label-box p{
  37. line-height: inherit;
  38. }
  39. .edui-default .edui-for-image .edui-icon{
  40. background-position: -380px 0px;
  41. }
  42. .file {
  43. position: relative;
  44. background: #0092DC;
  45. border: 1px solid #99D3F5;
  46. border-radius: 4px;
  47. padding: 7px 12px;
  48. overflow: hidden;
  49. color: #fff;
  50. text-decoration: none;
  51. text-indent: 0;
  52. line-height: 20px;
  53. width: 120px;
  54. }
  55. .file input {
  56. width: 100%;
  57. position: absolute;
  58. font-size: 5px;
  59. right: 0;
  60. top: 0;
  61. opacity: 0;
  62. }
  63. .file:hover {
  64. background: #AADFFD;
  65. border-color: #78C3F3;
  66. color: #004974;
  67. text-decoration: none;
  68. }
  69. .layui-form-select dl {
  70. z-index: 1000;
  71. }
  72. .layui-form-switch {
  73. box-sizing: content-box;
  74. }
  75. video {
  76. height: 100% !important;
  77. }
  78. .prism-player .prism-time-display {
  79. height: 39px;
  80. }
  81. .prism-player .prism-cc-btn, .prism-player .prism-setting-btn {
  82. display: none;
  83. }
  84. </style>
  85. <script type="text/javascript" charset="utf-8" src="{__ADMIN_PATH}plug/ueditor/third-party/zeroclipboard/ZeroClipboard.js"></script>
  86. <script type="text/javascript" charset="utf-8" src="{__ADMIN_PATH}plug/ueditor/ueditor.config.js"></script>
  87. <script type="text/javascript" charset="utf-8" src="{__ADMIN_PATH}plug/ueditor/ueditor.all.min.js"></script>
  88. <script src="{__ADMIN_PATH}plug/aliyun-upload-sdk/aliyun-upload-sdk-1.5.0.min.js"></script>
  89. <script src="{__ADMIN_PATH}plug/aliyun-upload-sdk/lib/es6-promise.min.js"></script>
  90. <script src="{__ADMIN_PATH}plug/aliyun-upload-sdk/lib/aliyun-oss-sdk-5.3.1.min.js"></script>
  91. <script src="//g.alicdn.com/de/prismplayer/2.9.21/aliplayer-min.js"></script>
  92. {/block}
  93. {block name="content"}
  94. <div v-cloak id="app" class="layui-fluid">
  95. <div class="layui-card">
  96. <div class="layui-card-body">
  97. <form action="" class="layui-form" lay-filter="taskForm">
  98. <div class="layui-form-item">
  99. <label class="layui-form-label">素材类型:</label>
  100. <div class="layui-input-block">
  101. <input type="radio" name="source_type" lay-filter="source_type" v-model="source_type" value="1" title="图文">
  102. <input type="radio" name="source_type" lay-filter="source_type" v-model="source_type" value="2" title="音频">
  103. <input type="radio" name="source_type" lay-filter="source_type" v-model="source_type" value="3" title="视频">
  104. </div>
  105. </div>
  106. <div class="layui-form-item">
  107. <label class="layui-form-label required">素材名称:</label>
  108. <div class="layui-input-block">
  109. <input type="text" name="title" v-model.trim="formData.title" autocomplete="off" placeholder="请输入素材名称" maxlength="50" class="layui-input">
  110. </div>
  111. </div>
  112. <div class="layui-form-item submit">
  113. <label class="layui-form-label">素材分类:</label>
  114. <div class="layui-input-block">
  115. <select name="pid" v-model="formData.pid" lay-search="" lay-filter="pid" >
  116. <option v-for="item in cateList" :value="item.id" >{{item.html}}{{item.title}}</option>
  117. </select>
  118. </div>
  119. </div>
  120. <div class="layui-form-item">
  121. <label class="layui-form-label">素材排序:</label>
  122. <div class="layui-input-inline">
  123. <input type="number" name="sort" v-model="formData.sort" autocomplete="off" min="0" class="layui-input" v-sort>
  124. </div>
  125. </div>
  126. <div class="layui-form-item required">
  127. <label class="layui-form-label">
  128. <div>
  129. <div>素材封面:</div>
  130. <div>(710*400)</div>
  131. </div>
  132. </label>
  133. <div class="layui-input-inline">
  134. <div class="upload-picture-card">
  135. <ul v-if="formData.image" class="upload-list">
  136. <li class="upload-item">
  137. <img class="upload-thumb" :src="formData.image">
  138. <div class="upload-action">
  139. <i class="fa fa-search-plus" @click="look(formData.image)"></i>
  140. <i class="fa fa-trash" @click="del('image')"></i>
  141. </div>
  142. </li>
  143. </ul>
  144. <div v-else class="upload-picture" @click="upload('image')">
  145. <i class="fa fa-plus"></i>
  146. </div>
  147. </div>
  148. </div>
  149. </div>
  150. <div class="layui-form-item" v-show="source_type==3">
  151. <label class="layui-form-label">素材链接:</label>
  152. <div class="layui-input-block">
  153. <input type="text" name="title" v-model.trim="link" style="width:50%;display:inline-block;margin-right: 10px;" autocomplete="off" placeholder="请输入视频链接" class="layui-input">
  154. <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" @click="confirmAdd()" v-show="is_upload==false">确认添加</button>
  155. <button v-show="is_upload==false" type="button" class="layui-btn layui-btn-normal layui-btn-sm ossupload" id="ossupload_video">上传视频</button>
  156. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" v-show="is_upload" @click="delVideo()">删除</button>
  157. <button v-show="link" type="button" class="layui-btn layui-btn-warm layui-btn-sm" @click="previewSource">预览</button>
  158. </div>
  159. <div class="layui-input-block" style="width: 50%;margin-top: 20px" v-show="is_video">
  160. <div class="layui-progress" style="margin-bottom: 10px">
  161. <div class="layui-progress-bar layui-bg-blue" :style="'width:'+videoWidth+'%'"></div>
  162. </div>
  163. <button type="button" class="layui-btn layui-btn-sm layui-btn-danger"
  164. @click="cancelUpload" v-show="demand_switch==2 && is_video">取消
  165. </button>
  166. <button type="button" class="authUpload layui-btn layui-btn-sm layui-btn-danger" v-show="demand_switch==1 && is_video">开始上传
  167. </button>
  168. <button type="button" class="pauseUpload layui-btn layui-btn-sm layui-btn-danger"
  169. v-show="demand_switch==1 && is_video">暂停
  170. </button>
  171. <button type="button" class="resumeUpload layui-btn layui-btn-sm layui-btn-danger" v-show="is_suspend"
  172. >恢复上传
  173. </button>
  174. </div>
  175. <div class="layui-form-mid layui-word-aux" style="margin-left: 0;">输入链接将视为添加视频直接添加,请确保视频链接的正确性</div>
  176. </div>
  177. <div class="layui-form-item" v-show="source_type==2">
  178. <label class="layui-form-label">素材链接:</label>
  179. <div class="layui-input-block">
  180. <input type="text" name="title" v-model.trim="link" style="width:50%;display:inline-block;margin-right: 10px;" autocomplete="off" placeholder="请输入音频链接" class="layui-input">
  181. <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" @click="confirmAdd()" v-show="is_upload==false">确认添加</button>
  182. <button v-show="is_upload==false" type="button" class="layui-btn layui-btn-normal layui-btn-sm ossupload" id="ossupload_audio">上传音频</button>
  183. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" v-show="is_upload" @click="delVideo()">删除</button>
  184. <button v-show="link" type="button" class="layui-btn layui-btn-warm layui-btn-sm" @click="previewSource">预览</button>
  185. </div>
  186. <div class="layui-input-block" style="width: 50%;margin-top: 20px" v-show="is_video">
  187. <div class="layui-progress" style="margin-bottom: 10px">
  188. <div class="layui-progress-bar layui-bg-blue" :style="'width:'+videoWidth+'%'"></div>
  189. </div>
  190. <button type="button" class="layui-btn layui-btn-sm layui-btn-danger"
  191. @click="cancelUpload" v-show="demand_switch==2 && is_video">取消
  192. </button>
  193. <button type="button" class="authUpload layui-btn layui-btn-sm layui-btn-danger" v-show="demand_switch==1 && is_video">开始上传
  194. </button>
  195. <button type="button" class="pauseUpload layui-btn layui-btn-sm layui-btn-danger"
  196. v-show="demand_switch==1 && is_video">暂停
  197. </button>
  198. <button type="button" class="resumeUpload layui-btn layui-btn-sm layui-btn-danger" v-show="is_suspend"
  199. >恢复上传
  200. </button>
  201. </div>
  202. <div class="layui-form-mid layui-word-aux" style="margin-left: 0;">输入链接将视为添加音频直接添加,请确保音频链接的正确性</div>
  203. </div>
  204. <div class="layui-form-item">
  205. <label class="layui-form-label">试{{ source_type == 2 ? '听' : '看' }}:</label>
  206. <div class="layui-input-block">
  207. <input :checked="formData.is_try" type="checkbox" name="is_try" lay-skin="switch" lay-text="开启|关闭" lay-filter="isTry">
  208. </div>
  209. </div>
  210. <div v-show="formData.is_try && source_type != 1" class="layui-form-item required">
  211. <label class="layui-form-label">试{{ source_type == 2 ? '听' : '看' }}时间:</label>
  212. <div class="layui-input-inline">
  213. <input v-model.number="formData.try_time" type="number" min="1" max="60" class="layui-input">
  214. </div>
  215. <div class="layui-form-mid layui-word-aux">分钟</div>
  216. </div>
  217. <div v-show="formData.is_try && source_type == 1" class="layui-form-item required">
  218. <label class="layui-form-label">试看内容:</label>
  219. <div class="layui-input-block">
  220. <textarea id="editor3">{{ formData.try_content }}</textarea>
  221. </div>
  222. </div>
  223. <div v-show="source_type==1" class="layui-form-item required">
  224. <label class="layui-form-label">素材内容:</label>
  225. <div class="layui-input-block">
  226. <textarea id="editor1">{{formData.content}}</textarea>
  227. </div>
  228. </div>
  229. <div class="layui-form-item required">
  230. <label class="layui-form-label">素材简介:</label>
  231. <div class="layui-input-block">
  232. <textarea id="editor2">{{formData.detail}}</textarea>
  233. </div>
  234. </div>
  235. <div class="layui-form-item submit">
  236. <div class="layui-input-block">
  237. <button class="layui-btn layui-btn-normal" type="button" @click="save">{$id ? '确认修改':'立即提交'}</button>
  238. <button class="layui-btn layui-btn-primary clone" type="button" @click="clone_form">取消</button>
  239. </div>
  240. </div>
  241. </form>
  242. </div>
  243. </div>
  244. <div class="prism-player" id="J_prismPlayer"></div>
  245. </div>
  246. <script type="text/javascript" src="{__ADMIN_PATH}js/layuiList.js"></script>
  247. {/block}
  248. {block name='script'}
  249. <script>
  250. var id={$id},special_id={$special_id},alicloud_account_id="{$alicloud_account_id}",configuration_item_region="{$configuration_item_region}",demand_switch="{$demand_switch}",
  251. special=<?=isset($special) ? $special : "{}"?>;
  252. require(['vue','zh-cn','request','aliyun-oss','plupload','OssUpload'],function(Vue) {
  253. new Vue({
  254. el: "#app",
  255. directives: {
  256. sort: {
  257. bind: function (el, binding, vnode) {
  258. var vm = vnode.context;
  259. el.addEventListener('change', function () {
  260. if (!this.value || this.value < 0) {
  261. vm.formData.sort = 0;
  262. } else if (this.value > 9999) {
  263. vm.formData.sort = 9999;
  264. } else {
  265. vm.formData.sort = parseInt(this.value);
  266. }
  267. });
  268. }
  269. }
  270. },
  271. data: {
  272. formData:{
  273. title:special.title || '',
  274. image:special.image ? special.image['pic'] : '',
  275. sort:special.sort || 0,
  276. pid:special.pid || 0,
  277. special_id:special.special_id || special_id,
  278. content:special.content,
  279. detail:special.detail ? (special.detail || '') : '',
  280. link:special.link ? (special.link || '') : '',
  281. videoId:special.videoId ? (special.videoId || '') : '',
  282. file_type:special.file_type ? (special.file_type || '') : '',
  283. file_name:special.file_name ? (special.file_name || '') : '',
  284. is_try: special.is_try || 0,
  285. try_time: special.try_time || 1,
  286. try_content: special.try_content || ''
  287. },
  288. source_type:special.type ? special.type : 1,
  289. but_title:'上传音频',
  290. link:'',
  291. host: ossUpload.host + '/',
  292. mask:{
  293. image:false,
  294. },
  295. ue:null,
  296. is_video:false,
  297. is_suspend:false,
  298. is_upload:false,
  299. demand_switch:demand_switch,
  300. //上传类型
  301. mime_types:{
  302. Image:"jpg,gif,png,JPG,GIF,PNG",
  303. Video:"mp4,MP4,mp3,MP3",
  304. },
  305. videoWidth:0,
  306. uploader:null,
  307. cateList:[]
  308. },
  309. methods:{
  310. // 预览音视频
  311. previewSource: function () {
  312. if (this.link.indexOf('http')) {
  313. layList.msg('请输入正确的'+ (this.source_type == '2' ? '音' : '视') +'频链接');
  314. } else {
  315. this.isPreview = true;
  316. if (this.formData.videoId) {
  317. this.playbackAddress(this.formData.videoId);
  318. } else {
  319. this.previewPlayer();
  320. }
  321. }
  322. },
  323. previewPlayer: function () {
  324. var that = this;
  325. new Aliplayer({
  326. id: 'J_prismPlayer',
  327. source: this.link,
  328. height: '100%',
  329. cover: this.source_type == '2' ? '' : this.formData.image,
  330. autoplay: false,
  331. format: this.source_type == '2' ? 'mp3' : ''
  332. }, function (player) {
  333. that.isPreview = false;
  334. layList.layer.open({
  335. type: 1,
  336. title: false,
  337. resize: false,
  338. content: $('#J_prismPlayer'),
  339. area: ['500px', '300px'],
  340. end: function () {
  341. player.dispose();
  342. }
  343. });
  344. });
  345. },
  346. //取消
  347. cancelUpload:function(){
  348. this.uploader.stop();
  349. this.is_video = false;
  350. this.videoWidth = 0;
  351. this.is_upload = false;
  352. },
  353. //删除图片
  354. del:function(key, index){
  355. var that = this;
  356. if(index != undefined){
  357. that.formData[key].splice(index,1);
  358. that.$set(that.formData,key,that.formData[key]);
  359. }else{
  360. that.$set(that.formData,key,'');
  361. }
  362. },
  363. //查看图片
  364. look:function(pic){
  365. layer.photos({
  366. photos: {
  367. data: [
  368. {
  369. src: pic
  370. }
  371. ]
  372. },
  373. anim: 5
  374. });
  375. },
  376. //鼠标移入事件
  377. enter:function(item){
  378. if(item){
  379. item.is_show = true;
  380. }else{
  381. this.mask = true;
  382. }
  383. },
  384. //鼠标移出事件
  385. leave:function(item){
  386. if(item){
  387. item.is_show = false;
  388. }else{
  389. this.mask = false;
  390. }
  391. },
  392. changeIMG:function(key,value,multiple){
  393. if(multiple){
  394. var that = this;
  395. value.map(function (v) {
  396. that.formData[key].push({pic:v,is_show:false});
  397. });
  398. this.$set(this.formData,key,this.formData[key]);
  399. }else{
  400. this.$set(this.formData,key,value);
  401. }
  402. },
  403. confirmAdd:function(){
  404. var that = this;
  405. if(that.link.substr(0,7).toLowerCase() == "http://" || that.link.substr(0,8).toLowerCase() == "https://"){
  406. that.is_upload=true;
  407. that.uploadVideo();
  408. }else{
  409. if(this.source_type==2){
  410. layList.msg('请输入正确的音频链接');
  411. }else if(this.source_type==3){
  412. layList.msg('请输入正确的视频链接');
  413. }
  414. }
  415. },
  416. uploadVideo:function(){
  417. if(this.link.substr(0,7).toLowerCase() == "http://" || this.link.substr(0,8).toLowerCase() == "https://"){
  418. this.setContent(this.link);
  419. }else{
  420. if(this.source_type==2){
  421. layList.msg('请输入正确的音频链接');
  422. }else if(this.source_type==3){
  423. layList.msg('请输入正确的视频链接');
  424. }
  425. }
  426. },
  427. setContent:function(link){
  428. this.formData.link = link;
  429. },
  430. //上传图片
  431. upload:function(key,count){
  432. ossUpload.createFrame('请选择图片',{fodder:key,max_count:count === undefined ? 0 : count},{w:800,h:550});
  433. },
  434. save:function () {
  435. var that=this;
  436. that.formData.detail = that.editor2.getContent();
  437. if(!that.formData.title) return layList.msg('请输入素材名称');
  438. if(!that.formData.image) return layList.msg('请输入素材封面');
  439. if (that.source_type != 1) {
  440. if (that.demand_switch == '1') {
  441. if (that.formData.videoId) {
  442. that.formData.link = '';
  443. } else if (that.formData.link) {
  444. that.formData.videoId = '';
  445. that.formData.file_type = '';
  446. that.formData.file_name = '';
  447. }
  448. } else if (that.demand_switch == '2') {
  449. if (that.formData.videoId) {
  450. that.formData.link = '';
  451. } else {
  452. that.formData.videoId = '';
  453. that.formData.file_type = '';
  454. that.formData.file_name = '';
  455. if (!that.formData.link) {
  456. return layList.msg('请上传素材');
  457. }
  458. }
  459. }
  460. if (!that.formData.link && !that.formData.videoId) {
  461. return layList.msg('请上传素材2');
  462. }
  463. }
  464. if (this.formData.is_try) {
  465. if (that.source_type == 1) {
  466. that.formData.try_content = that.editor3.getContent();
  467. if (!that.formData.try_content) {
  468. return layList.msg('请编辑试看内容');
  469. }
  470. } else {
  471. if (typeof that.formData.try_time == 'number') {
  472. that.formData.try_time = that.formData.try_time.toString();
  473. }
  474. if (that.formData.try_time) {
  475. if (isNaN(that.formData.try_time)) {
  476. return layList.msg('请输入正确的试' + (that.source_type == 2 ? '听' : '看') + '时间');
  477. } else {
  478. if (parseInt(that.formData.try_time) == parseFloat(that.formData.try_time)) {
  479. that.formData.try_time = parseInt(that.formData.try_time).toString();
  480. if (that.formData.try_time < 1) {
  481. return layList.msg('请输入不小于1的试' + (that.source_type == 2 ? '听' : '看') + '时间');
  482. } else {
  483. if (that.formData.try_time > 60) {
  484. return layList.msg('请输入不大于60的试' + (that.source_type == 2 ? '听' : '看') + '时间');
  485. }
  486. }
  487. } else {
  488. return layList.msg('请输入整数的试' + (that.source_type == 2 ? '听' : '看') + '时间');
  489. }
  490. }
  491. } else {
  492. return layList.msg('请输入试' + (that.source_type == 2 ? '听' : '看') + '时间');
  493. }
  494. }
  495. }
  496. if (that.source_type == 1) {
  497. that.formData.content = that.editor1.getContent();
  498. if (!that.formData.content) {
  499. return layList.msg('请编辑素材内容');
  500. }
  501. }
  502. if (!that.formData.detail) {
  503. return layList.msg('请编辑素材简介');
  504. }
  505. layList.loadFFF();
  506. layList.basePost(layList.U({a:'save_source',q:{id:id,special_type:that.source_type}}),that.formData,function (res) {
  507. layList.loadClear();
  508. if(parseInt(id) == 0) {
  509. if (that.source_type == 1) {
  510. layList.layer.confirm('添加成功,您要继续添加素材吗?', {
  511. btn: ['继续添加', '立即提交'] //按钮
  512. }, function (index) {
  513. layList.layer.close(index);
  514. }, function () {
  515. parent.layer.closeAll();
  516. });
  517. } else {
  518. if (that.demand_switch == '1') {
  519. layList.layer.alert('添加成功。', { closeBtn: 0 }, function (index) {
  520. parent.layer.closeAll();
  521. });
  522. } else {
  523. layList.layer.confirm('添加成功,您要继续添加素材吗?', {
  524. btn: ['继续添加', '立即提交'] //按钮
  525. }, function (index) {
  526. layList.layer.close(index);
  527. }, function () {
  528. parent.layer.closeAll();
  529. });
  530. }
  531. }
  532. }else{
  533. layer.msg('修改成功',{icon:1},function () {
  534. parent.layer.closeAll();
  535. });
  536. }
  537. },function (res) {
  538. layList.msg(res.msg);
  539. layList.loadClear();
  540. });
  541. },
  542. clone_form:function () {
  543. if(parseInt(id) == 0){
  544. var that = this;
  545. if(that.formData.image) return layList.msg('请先删除上传的图片在尝试取消');
  546. parent.layer.closeAll();
  547. }
  548. parent.layer.closeAll();
  549. },
  550. //获取素材分类
  551. get_subject_list: function () {
  552. var that = this;
  553. layList.baseGet(layList.U({c:'special.special_task_category',a: 'get_cate_list'}), function (res) {
  554. that.$set(that, 'cateList', res.data);
  555. that.$nextTick(function () {
  556. layList.form.render('select');
  557. })
  558. });
  559. },
  560. createUploader:function () {
  561. var that=this;
  562. var uploader = new AliyunUpload.Vod({
  563. timeout: 60000,//请求过期时间(配置项 timeout, 默认 60000)
  564. partSize: 1048576,//分片大小(配置项 partSize, 默认 1048576)
  565. parallel: 5,//上传分片数(配置项 parallel, 默认 5)
  566. retryCount:3,//网络失败重试次数(配置项 retryCount, 默认 3)
  567. retryDuration:2,//网络失败重试间隔(配置项 retryDuration, 默认 2)
  568. region: configuration_item_region,//配置项 region, 默认 cn-shanghai
  569. userId: alicloud_account_id,//阿里云账号ID
  570. // 添加文件成功
  571. addFileSuccess: function (uploadInfo) {
  572. if (alicloud_account_id=='') {
  573. return layList.msg('请配置阿里云账号ID!');
  574. }
  575. var type=uploadInfo.file.type;
  576. var arr=type.split('/');
  577. if(that.source_type==2 && arr[0]!='audio'){
  578. that.is_video=false;
  579. that.videoWidth = 0;
  580. return layList.msg('请上传音频');
  581. }else if(that.source_type==3 && arr[0]!='video'){
  582. that.is_video=false;
  583. that.videoWidth = 0;
  584. return layList.msg('请上传视频');
  585. }else{
  586. that.is_video=true;
  587. that.videoWidth = 0;
  588. }
  589. },
  590. // 开始上传
  591. onUploadstarted: function (uploadInfo) {
  592. var videoId='';
  593. if(uploadInfo.videoId){
  594. videoId= uploadInfo.videoId;
  595. }
  596. layList.basePost(layList.U({a: 'video_upload_address_voucher'}),
  597. {
  598. FileName:uploadInfo.file.name,type:1,image:that.formData.image,videoId:videoId
  599. }, function (res) {
  600. var url=res.msg;
  601. $.ajax({
  602. url:url,
  603. data:{},
  604. type:"GET",
  605. dataType:'json',
  606. success:function (data) {
  607. if(data.RequestId){
  608. var uploadAuth = data.UploadAuth;
  609. var uploadAddress = data.UploadAddress;
  610. var videoId = data.VideoId;
  611. uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress,videoId)
  612. }
  613. },
  614. error:function (err) {
  615. return layList.msg(err.responseJSON.Message);
  616. }
  617. });
  618. });
  619. },
  620. // 文件上传成功
  621. onUploadSucceed: function (uploadInfo) {
  622. that.formData.videoId=uploadInfo.videoId;
  623. that.formData.file_name=uploadInfo.file.name;
  624. that.formData.file_type=uploadInfo.file.type;
  625. that.videoWidth = 0;
  626. that.is_video = false;
  627. that.is_suspend = false;
  628. that.is_upload = true;
  629. that.playbackAddress(uploadInfo.videoId);
  630. },
  631. // 文件上传失败
  632. onUploadFailed: function (uploadInfo, code, message) {
  633. },
  634. // 取消文件上传
  635. onUploadCanceled: function (uploadInfo, code, message) {
  636. that.formData.file_name='';
  637. that.is_suspend = false;
  638. },
  639. // 文件上传进度,单位:字节, 可以在这个函数中拿到上传进度并显示在页面上
  640. onUploadProgress: function (uploadInfo, totalSize, progress) {
  641. that.videoWidth = Math.ceil(progress * 100);
  642. },
  643. // 上传凭证超时
  644. onUploadTokenExpired: function (uploadInfo) {
  645. var videoId='';
  646. if(uploadInfo.videoId){
  647. videoId= uploadInfo.videoId;
  648. }
  649. layList.basePost(layList.U({a: 'video_upload_address_voucher'}),{
  650. FileName:uploadInfo.file.name,type:1,image:that.formData.image,videoId:videoId
  651. }, function (res) {
  652. var url=res.msg;
  653. $.ajax({
  654. url:url,
  655. data:{},
  656. type:"GET",
  657. dataType:'json',
  658. success:function (data) {
  659. if(data.RequestId){
  660. var uploadAuth = data.UploadAuth;
  661. uploader.resumeUploadWithAuth(uploadAuth);
  662. }
  663. },
  664. error:function (err) {
  665. return layList.msg(err.responseJSON.Message);
  666. }
  667. });
  668. });
  669. },
  670. // 全部文件上传结束
  671. onUploadEnd: function (uploadInfo) {
  672. that.videoWidth = 0;
  673. that.is_video = false;
  674. that.is_suspend = false;
  675. that.is_upload = true;
  676. console.log("onUploadEnd: uploaded all the files")
  677. }
  678. });
  679. return uploader;
  680. },
  681. delVideo:function(){
  682. var that=this;
  683. if(that.demand_switch=='1' && that.formData.videoId){
  684. layList.basePost(layList.U({a: 'video_upload_address_voucher'}),{
  685. FileName:'',type:4,image:'',videoId:that.formData.videoId
  686. }, function (res) {
  687. var url=res.msg;
  688. $.ajax({
  689. url:url,
  690. data:{},
  691. type:"GET",
  692. dataType:'json',
  693. success:function (data) {
  694. if(data.RequestId){
  695. that.link='';
  696. that.formData.content='';
  697. that.formData.videoId='';
  698. that.formData.file_type='';
  699. that.formData.file_name='';
  700. that.editor1.setContent('');
  701. $("input[type='file']").val('');
  702. that.is_upload = false;
  703. }
  704. },
  705. error:function (err) {
  706. return layList.msg(err.responseJSON.Message);
  707. }
  708. });
  709. });
  710. }else{
  711. that.formData.videoId='';
  712. that.link='';
  713. that.editor1.setContent('');
  714. that.is_upload = false;
  715. }
  716. },
  717. playbackAddress:function (videoId) {
  718. var that=this;
  719. if(videoId=='') return false;
  720. layList.basePost(layList.U({a: 'video_upload_address_voucher'}), {
  721. FileName: '', type: 3, image: '', videoId: videoId
  722. }, function (res) {
  723. var url = res.msg;
  724. $.ajax({
  725. url: url,
  726. data: {},
  727. type: "GET",
  728. dataType: 'json',
  729. success: function (data) {
  730. that.link = data.PlayInfoList.PlayInfo[0].PlayURL;
  731. if (that.isPreview) {
  732. that.previewPlayer();
  733. } else {
  734. that.uploadVideo();
  735. }
  736. },
  737. error: function (err) {
  738. that.link = '';
  739. that.formData.content = '';
  740. that.formData.videoId = '';
  741. that.formData.file_type = '';
  742. that.formData.file_name = '';
  743. that.is_upload = false;
  744. return layList.msg(err.responseJSON.Message);
  745. }
  746. });
  747. });
  748. },
  749. audio_video_upload:function () {
  750. var that=this;
  751. if (that.uploader) {
  752. that.uploader.destroy();
  753. }
  754. that.uploader = ossUpload.upload({
  755. id: that.source_type == 2 ? 'ossupload_audio' : 'ossupload_video',
  756. mime_types: [
  757. that.source_type == 2 ? {title: "Mp3 files", extensions: "mp3"} : {title: "Mp4 files", extensions: "mp4,m3u8"}
  758. ],
  759. FilesAddedSuccess: function () {
  760. that.is_video = true;
  761. },
  762. uploadIng: function (file) {
  763. that.videoWidth = file.percent;
  764. },
  765. success: function (res) {
  766. layList.msg('上传成功');
  767. that.videoWidth = 0;
  768. that.is_video = false;
  769. that.formData.videoId='';
  770. that.is_upload = true;
  771. that.link = res.url;
  772. that.uploadVideo();
  773. },
  774. fail: function (err) {
  775. that.videoWidth = 0;
  776. that.is_video = false;
  777. that.is_upload = false;
  778. layList.msg(err);
  779. }
  780. })
  781. }
  782. },
  783. mounted:function () {
  784. var that=this;
  785. that.get_subject_list();
  786. window.changeIMG = that.changeIMG;
  787. //实例化form
  788. layList.select('pid', function (obj) {
  789. that.formData.pid = obj.value;
  790. });
  791. layList.form.on('radio(source_type)', function (data) {
  792. that.source_type = parseInt(data.value);
  793. if(that.demand_switch=='1') {
  794. that.uploadInst.reload({
  795. accept: that.source_type == 2 ? 'audio' : 'video',
  796. acceptMime: that.source_type == 2 ? 'audio/mp3' : 'video/mp4,video/m3u8',
  797. exts: that.source_type == 2 ? 'mp3' : 'mp4|m3u8'
  798. });
  799. }
  800. if(that.demand_switch=='2') {
  801. that.audio_video_upload();
  802. }
  803. that.$nextTick(function () {
  804. layList.form.render('radio');
  805. });
  806. });
  807. //选择图片
  808. function changeIMG(index,pic){
  809. $(".image_img").css('background-image',"url("+pic+")");
  810. $(".active").css('background-image',"url("+pic+")");
  811. $('#image_input').val(pic);
  812. }
  813. //选择图片插入到编辑器中
  814. window.insertEditor = function(list,fodder){
  815. that[fodder].execCommand('insertimage', list);
  816. };
  817. if(that.formData.link && that.formData.videoId=='' && that.source_type!=1){
  818. that.is_upload=true;
  819. that.link = that.formData.link;
  820. }else if(that.formData.videoId && that.formData.link== '' && that.source_type!=1){
  821. that.is_upload=true;
  822. that.playbackAddress(that.formData.videoId);
  823. }
  824. this.$nextTick(function () {
  825. var form = layList.form;
  826. form.render();
  827. form.on('switch(isTry)', function (data) {
  828. that.formData.is_try = data.elem.checked ? 1 : 0;
  829. });
  830. //实例化编辑器
  831. UE.registerUI('选择图片', function (editor, uiName) {
  832. var btn = new UE.ui.Button({
  833. name: uiName,
  834. title: uiName,
  835. cssRules: 'background-position: -380px 0;',
  836. onclick: function() {
  837. ossUpload.createFrame(uiName, { fodder: editor.key }, { w: 800, h: 550 });
  838. }
  839. });
  840. return btn;
  841. });
  842. var textareaElements = document.getElementsByTagName('textarea');
  843. var textareaId = '';
  844. for (var i = textareaElements.length; i--;) {
  845. textareaId = textareaElements[i].id;
  846. that[textareaId] = UE.getEditor(textareaId);
  847. }
  848. });
  849. //图片上传和视频上传
  850. var uploader = null;
  851. if(that.demand_switch=='1'){
  852. that.uploadInst = layui.upload.render({
  853. elem: '.ossupload',
  854. accept: that.source_type == 2 ? 'audio' : 'video',
  855. acceptMime: that.source_type == 2 ? 'audio/mp3' : 'video/mp4,video/m3u8',
  856. exts: that.source_type == 2 ? 'mp3' : 'mp4|m3u8',
  857. auto: false,
  858. choose: function (obj) {
  859. obj.preview(function(index, file, result){
  860. var userData = '{"Vod":{}}';
  861. uploader = that.createUploader();
  862. uploader.addFile(file, null, null, null, userData);
  863. });
  864. }
  865. });
  866. // 第一种方式 UploadAuth 上传
  867. $('.authUpload').on('click', function () {
  868. if (uploader !== null) {
  869. uploader.startUpload();
  870. }
  871. });
  872. // 暂停上传
  873. $('.pauseUpload').on('click', function () {
  874. if (uploader !== null) {
  875. uploader.stopUpload();
  876. that.is_suspend = true;
  877. that.formData.file_name='';
  878. layList.msg('暂停上传!');
  879. }
  880. });
  881. //恢复上传
  882. $('.resumeUpload').on('click', function () {
  883. if (uploader !== null) {
  884. uploader.startUpload();
  885. that.is_suspend = false;
  886. layList.msg('恢复上传成功!');
  887. }
  888. });
  889. }else if(that.demand_switch=='2' && id>0){
  890. that.audio_video_upload();
  891. }
  892. }
  893. })
  894. })
  895. </script>
  896. {/block}