| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
- <link href="{__FRAME_PATH}css/font-awesome.min.css" rel="stylesheet">
- <link href="{__ADMIN_PATH}plug/umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
- <script type="text/javascript" src="{__ADMIN_PATH}plug/umeditor/third-party/jquery.min.js"></script>
- <script type="text/javascript" src="{__ADMIN_PATH}plug/umeditor/third-party/template.min.js"></script>
- <script type="text/javascript" charset="utf-8" src="{__ADMIN_PATH}plug/umeditor/umeditor.config.js"></script>
- <script type="text/javascript" charset="utf-8" src="{__ADMIN_PATH}plug/umeditor/umeditor.min.js"></script>
- <script type="text/javascript" src="{__ADMIN_PATH}plug/umeditor/lang/zh-cn/zh-cn.js"></script>
- <link rel="stylesheet" href="/static/plug/layui/css/layui.css">
- <link rel="stylesheet" href="{__PLUG_PATH}daterangepicker/daterangepicker.css">
- <script src="{__PLUG_PATH}moment.js"></script>
- <script src="{__PLUG_PATH}daterangepicker/daterangepicker.js"></script>
- <script src="/static/plug/layui/layui.js"></script>
- <script src="{__PLUG_PATH}vue/dist/vue.min.js"></script>
- <script src="/static/plug/axios.min.js"></script>
- <script src="{__MODULE_PATH}widget/aliyun-oss-sdk-4.4.4.min.js"></script>
- <script src="{__MODULE_PATH}widget/cos-js-sdk-v5.min.js"></script>
- <script src="{__MODULE_PATH}widget/qiniu-js-sdk-2.5.5.js"></script>
- <script src="{__MODULE_PATH}widget/plupload.full.min.js"></script>
- <style>
- .layui-form-item {
- margin-bottom: 0px;
- }
- .pictrueBox {
- display: inline-block !important;
- }
- .pictrue {
- width: 60px;
- height: 60px;
- border: 1px dotted rgba(0, 0, 0, 0.1);
- margin-right: 15px;
- display: inline-block;
- position: relative;
- cursor: pointer;
- }
- .pictrue img {
- width: 100%;
- height: 100%;
- }
- .upLoad {
- width: 58px;
- height: 58px;
- line-height: 58px;
- border: 1px dotted rgba(0, 0, 0, 0.1);
- border-radius: 4px;
- background: rgba(0, 0, 0, 0.02);
- cursor: pointer;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .rulesBox {
- display: flex;
- flex-wrap: wrap;
- margin-left: 10px;
- }
- .layui-tab-content {
- margin-top: 15px;
- }
- .ml110 {
- margin: 18px 0 4px 110px;
- }
- .rules {
- display: flex;
- }
- .rules-btn-sm {
- height: 30px;
- line-height: 30px;
- font-size: 12px;
- width: 109px;
- }
- .rules-btn-sm input {
- width: 79% !important;
- height: 84% !important;
- padding: 0 10px;
- }
- .ml10 {
- margin-left: 10px !important;
- }
- .ml40 {
- margin-left: 40px !important;
- }
- .closes {
- position: absolute;
- left: 86%;
- top: -18%;
- }
- .red {
- color: red;
- }
- .layui-input-block .layui-video-box {
- width: 22%;
- height: 180px;
- border-radius: 10px;
- background-color: #707070;
- margin-top: 10px;
- position: relative;
- overflow: hidden;
- }
- .layui-input-block .layui-video-box i {
- color: #fff;
- line-height: 180px;
- margin: 0 auto;
- width: 50px;
- height: 50px;
- display: inherit;
- font-size: 50px;
- }
- .layui-input-block .layui-video-box .mark {
- position: absolute;
- width: 100%;
- height: 30px;
- top: 0;
- background-color: rgba(0, 0, 0, .5);
- text-align: center;
- }
- .store_box {
- display: flex;
- }
- .info {
- color: #c9c9c9;
- padding-left: 10px;
- line-height: 30px;
- }
- </style>
- </head>
- <body>
- <div class="layui-fluid">
- <div class="layui-row layui-col-space15" id="app" v-cloak="">
- <div class="layui-card">
- <div class="layui-card-header">
- <span class="">{{id ? '帖子修改': '帖子添加' }}</span>
- <button style="margin-left: 20px" type="button" class="layui-btn layui-btn-primary layui-btn-xs"
- @click="goBack">返回列表
- </button>
- </div>
- <div class="layui-card-body">
- <form class="layui-form" action="" v-cloak="">
- <div class="layui-tab layui-tab-brief" lay-filter="docTabBrief">
- <!-- <ul class="layui-tab-title">-->
- <!-- <li class="layui-this" lay-id='1'>基础信息</li>-->
- <!-- <li lay-id='2'>活动详情</li>-->
- <!-- </ul>-->
- <div class="layui-tab-content">
- <div class="layui-tab-item layui-show">
- <div class="layui-row layui-col-space15">
- <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
- <div class="grid-demo grid-demo-bg1">
- <div class="layui-form-item">
- <label class="layui-form-label">帖子标题<i class="red">*</i></label>
- <div class="layui-input-block">
- <input type="text" name="title" lay-verify="title"
- autocomplete="off"
- placeholder="请输入帖子标题" class="layui-input"
- v-model="formData.title" maxlength="100">
- </div>
- </div>
- </div>
- </div>
- <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
- <div class="grid-demo grid-demo-bg1">
- <div class="layui-form-item">
- <label class="layui-form-label">产品标题<i class="red">*</i></label>
- <div class="layui-input-block">
- <input type="text" name="product_title" lay-verify="product_title"
- autocomplete="off"
- placeholder="请输入产品标题" class="layui-input"
- v-model="formData.product_title" maxlength="100">
- </div>
- </div>
- </div>
- </div>
- <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
- <div class="grid-demo grid-demo-bg1">
- <div class="layui-form-item">
- <label class="layui-form-label">产品链接<i class="red">*</i></label>
- <div class="layui-input-block">
- <input type="text" name="product_url" lay-verify="product_url"
- autocomplete="off"
- placeholder="请输入产品链接" class="layui-input"
- v-model="formData.product_url" maxlength="100">
- </div>
- </div>
- </div>
- </div>
- <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
- <div class="grid-demo grid-demo-bg1">
- <div class="layui-form-item">
- <label class="layui-form-label">帖子图片列表<i class="red">*</i></label>
- <div class="pictrueBox pictrue"
- v-for="(item,index) in formData.img_list">
- <img :src="item">
- <i class="layui-icon closes"
- @click="deleteImage('img_list',index)">ဇ</i>
- </div>
- <div class="pictrueBox">
- <div class="upLoad" @click="uploadImage('img_list')"
- v-if="formData.img_list.length <= rule.img_list.maxLength">
- <i class="layui-icon layui-icon-camera" class="iconfont"
- style="font-size: 26px;"></i>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="layui-row layui-col-space15">
- <div class="layui-form-item">
- <textarea type="text/plain" name="content" id="myEditor"
- style="width:60%;">{{formData.content}}</textarea>
- </div>
- </div>
- </div>
- </div>
- <!-- <div class="layui-tab-item">-->
- <!---->
- <!-- </div>-->
- </div>
- <div class="layui-tab-content">
- <div class="layui-row layui-col-space15">
- <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
- <div class="grid-demo grid-demo-bg1">
- <div class="layui-form-item" v-if="id">
- <button class="layui-btn layui-btn-primary layui-btn-sm" type="button"
- @click="handleSubmit()">保存
- </button>
- <!-- <button class="layui-btn layui-btn-primary layui-btn-sm" type="button"-->
- <!-- @click="back" v-if="layTabId != 1">上一步-->
- <!-- </button>-->
- <!-- <button class="layui-btn layui-btn-normal layui-btn-sm" type="button"-->
- <!-- v-if="layTabId != 2" @click="next">下一步-->
- </button>
- </div>
- <div class="layui-form-item" v-else>
- <!-- <button class="layui-btn layui-btn-primary layui-btn-sm" type="button"-->
- <!-- @click="back" v-if="layTabId != 1">上一步-->
- <!-- </button>-->
- <!-- <button class="layui-btn layui-btn-normal layui-btn-sm" type="button"-->
- <!-- @click="next" v-if="layTabId != 2">下一步-->
- <!-- </button>-->
- <button class="layui-btn layui-btn-normal layui-btn-sm" type="button"
- @click="handleSubmit()">提交
- </button>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </form>
- </div>
- </div>
- </div>
- </div>
- <script>
- var id = {$id};
- new Vue({
- el: '#app',
- data: {
- id: id,
- upload: {
- videoIng: false
- },
- formData: {
- title: '',
- img_list: [],
- content: '',
- product_title: '',
- product_url: '',
- },
- rule: { //多图选择规则
- img_list: {
- maxLength: 5
- }
- },
- progress: 0,
- um: null,//编译器实例化
- form: null,//layui.form
- layTabId: 1,
- ruleBool: id ? true : false,
- },
- methods: {
- back: function () {
- var that = this;
- layui.use(['element'], function () {
- layui.element.tabChange('docTabBrief', that.layTabId == 1 ? 1 : parseInt(that.layTabId) - 1);
- });
- },
- next: function () {
- var that = this;
- layui.use(['element'], function () {
- layui.element.tabChange('docTabBrief', that.layTabId == 2 ? 2 : parseInt(that.layTabId) + 1);
- });
- },
- goBack: function () {
- location.href = this.U({c: 'qa.Questions', a: 'index'});
- },
- U: function (opt) {
- var m = opt.m || 'admin', c = opt.c || window.controlle || '', a = opt.a || 'index', q = opt.q || '',
- p = opt.p || {};
- var params = Object.keys(p).map(function (key) {
- return key + '/' + p[key];
- }).join('/');
- var gets = Object.keys(q).map(function (key) {
- return key + '=' + q[key];
- }).join('&');
- return '/' + m + '/' + c + '/' + a + (params == '' ? '' : '/' + params) + (gets == '' ? '' : '?' + gets);
- },
- /**
- * 提示
- * */
- showMsg: function (msg, success) {
- layui.use(['layer'], function () {
- layui.layer.msg(msg, success);
- });
- },
- /**
- * 获取活动信息
- * */
- getQuestionsInfo: function () {
- var that = this;
- that.requestGet(that.U({
- c: "qa.Questions",
- a: 'get_questions_info',
- q: {id: that.id}
- })).then(function (res) {
- var questionsInfo = res.data.questionsInfo || {};
- if (questionsInfo.id && that.id) {
- that.$set(that, 'formData', questionsInfo);
- // that.formData.start_time = formatDate(that.formData.start_time * 1000);
- // that.formData.end_time = formatDate(that.formData.end_time * 1000);
- }
- that.init();
- }).catch(function (res) {
- that.showMsg(res.msg);
- })
- },
- /**
- * 删除图片
- * */
- deleteImage: function (key, index) {
- var that = this;
- if (index != undefined) {
- that.formData[key].splice(index, 1);
- that.$set(that.formData, key, that.formData[key]);
- } else {
- that.$set(that.formData, key, '');
- }
- },
- createFrame: function (title, src, opt) {
- opt === undefined && (opt = {});
- var h = 0;
- if (window.innerHeight < 800 && window.innerHeight >= 700) {
- h = window.innerHeight - 50;
- } else if (window.innerHeight < 900 && window.innerHeight >= 800) {
- h = window.innerHeight - 100;
- } else if (window.innerHeight < 1000 && window.innerHeight >= 900) {
- h = window.innerHeight - 150;
- } else if (window.innerHeight >= 1000) {
- h = window.innerHeight - 200;
- } else {
- h = window.innerHeight;
- }
- var area = [(opt.w || window.innerWidth / 2) + 'px', (!opt.h || opt.h > h ? h : opt.h) + 'px'];
- layui.use('layer', function () {
- return layer.open({
- type: 2,
- title: title,
- area: area,
- fixed: false, //不固定
- maxmin: true,
- moveOut: false,//true 可以拖出窗外 false 只能在窗内拖
- anim: 5,//出场动画 isOutAnim bool 关闭动画
- offset: 'auto',//['100px','100px'],//'auto',//初始位置 ['100px','100px'] t[ 上 左]
- shade: 0,//遮罩
- resize: true,//是否允许拉伸
- content: src,//内容
- move: '.layui-layer-title'
- });
- });
- },
- changeIMG: function (name, value) {
- if (this.getRule(name).maxLength !== undefined) {
- var that = this;
- value.map(function (v) {
- that.formData[name].push(v);
- });
- this.$set(this.formData, name, this.formData[name]);
- } else {
- if (name == 'batchAttr.pic') {
- this.batchAttr.pic = value;
- } else {
- if (name.indexOf('.') !== -1) {
- var key = name.split('.');
- if (key.length == 2) {
- this.formData[key[0]][key[1]] = value;
- } else if (key.length == 3) {
- this.formData[key[0]][key[1]][key[2]] = value;
- } else if (key.length == 4) {
- this.$set(this.formData[key[0]][key[1]][key[2]], key[3], value)
- }
- } else {
- this.formData[name] = value;
- }
- }
- }
- },
- getRule: function (name) {
- return this.rule[name] || {};
- },
- uploadImage: function (name) {
- return this.createFrame('选择图片', this.U({c: "widget.images", a: 'index', p: {fodder: name}}), {
- h: 545,
- w: 900
- });
- },
- insertEditor: function (list) {
- this.um.execCommand('insertimage', list);
- },
- getContent: function () {
- return this.um.getContent();
- },
- /**
- * 监听radio字段
- */
- // eeventRadio: function () {
- // var that = this;
- // that.radioRule.map(function (val) {
- // that.form.on('radio(' + val + ')', function (res) {
- // that.formData[val] = res.value;
- // });
- // })
- // },
- init: function () {
- var that = this;
- window.UMEDITOR_CONFIG.toolbar = [
- // 加入一个 test
- 'source | undo redo | bold italic underline strikethrough | superscript subscript | forecolor backcolor | removeformat |',
- 'insertorderedlist insertunorderedlist | selectall cleardoc paragraph | fontfamily fontsize',
- '| justifyleft justifycenter justifyright justifyjustify |',
- 'link unlink | emotion selectimgs video | map',
- '| horizontal print preview fullscreen', 'drafts', 'formula'
- ];
- UM.registerUI('selectimgs', function (name) {
- var me = this;
- var $btn = $.eduibutton({
- icon: 'image',
- click: function () {
- that.createFrame('选择图片', "{:Url('widget.images/index',['fodder'=>'editor'])}");
- },
- title: '选择图片'
- });
- this.addListener('selectionchange', function () {
- //切换为不可编辑时,把自己变灰
- var state = this.queryCommandState(name);
- $btn.edui().disabled(state == -1).active(state == 1)
- });
- return $btn;
- });
- //实例化编辑器
- this.um = UM.getEditor('myEditor', {initialFrameWidth: '99%', initialFrameHeight: 400});
- this.um.setContent(that.formData.content);
- that.$nextTick(function () {
- layui.use(['form', 'element'], function () {
- that.form = layui.form;
- that.form.render();
- that.form.on('select(temp_id)', function (data) {
- that.$set(that.formData, 'temp_id', data.value);
- });
- that.form.on('select(rule_index)', function (data) {
- that.ruleIndex = data.value;
- });
- layui.element.on('tab(docTabBrief)', function () {
- that.layTabId = this.getAttribute('lay-id');
- });
- // that.eeventRadio();
- });
- })
- },
- requestPost: function (url, data) {
- return new Promise(function (resolve, reject) {
- axios.post(url, data).then(function (res) {
- if (res.status == 200 && res.data.code == 200) {
- resolve(res.data)
- } else {
- reject(res.data);
- }
- }).catch(function (err) {
- reject({msg: err})
- });
- })
- },
- requestGet: function (url) {
- return new Promise(function (resolve, reject) {
- axios.get(url).then(function (res) {
- if (res.status == 200 && res.data.code == 200) {
- resolve(res.data)
- } else {
- reject(res.data);
- }
- }).catch(function (err) {
- reject({msg: err})
- });
- })
- },
- handleSubmit: function () {
- var that = this;
- if (!that.formData.title.length) {
- return that.showMsg('请填写帖子名称');
- }
- // if (!that.formData.pay_price.length) {
- // return that.showMsg('请填写报名费');
- // }
- if (!that.formData.product_title.length) {
- return that.showMsg('请填写产品标题');
- }
- if (!that.formData.product_url.length) {
- return that.showMsg('请填写产品链接');
- }
- if (!that.formData.img_list.length) {
- return that.showMsg('请选择帖子图片');
- }
- that.formData.content = that.getContent();
- if (!that.formData.content.length) {
- return that.showMsg('请填写帖子详情');
- }
- that.requestPost(that.U({
- c: 'qa.Questions',
- a: 'save',
- p: {id: that.id}
- }), that.formData).then(function (res) {
- that.confirm();
- }).catch(function (res) {
- that.showMsg(res.msg);
- });
- },
- confirm: function () {
- var that = this;
- layui.use(['layer'], function () {
- var layer = layui.layer;
- layer.confirm(that.id ? '修改成功是否返回帖子列表' : '添加成功是否返回帖子列表', {
- btn: ['返回列表', that.id ? '继续修改' : '继续添加'] //按钮
- }, function () {
- location.href = that.U({c: 'qa.Questions', a: 'index'});
- }, function () {
- if (that.id == 0) {
- location.reload();
- }
- });
- });
- },
- render: function () {
- this.$nextTick(function () {
- layui.use(['form'], function () {
- layui.form.render('select');
- });
- })
- },
- // 移动
- handleDragStart(e, item) {
- this.dragging = item;
- },
- handleDragEnd(e, item) {
- this.dragging = null
- },
- handleDragOver(e) {
- e.dataTransfer.dropEffect = 'move'
- },
- handleDragEnter(e, item) {
- e.dataTransfer.effectAllowed = 'move'
- if (item === this.dragging) {
- return
- }
- var newItems = [...this.formData.activity];
- var src = newItems.indexOf(this.dragging);
- var dst = newItems.indexOf(item);
- newItems.splice(dst, 0, ...newItems.splice(src, 1))
- this.formData.activity = newItems;
- }
- },
- mounted: function () {
- var that = this;
- axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
- that.getQuestionsInfo();
- window.$vm = that;
- window.changeIMG = that.changeIMG;
- window.insertEditor = that.insertEditor;
- window.insertEditorVideo = that.insertEditorVideo;
- $(that.$refs.filElem).change(function () {
- var inputFile = this.files[0];
- that.requestPost(that.U({c: "widget.video", a: 'get_signature'})).then(function (res) {
- AdminUpload.upload(res.data.uploadType, {
- token: res.data.uploadToken || '',
- file: inputFile,
- accessKeyId: res.data.accessKey || '',
- accessKeySecret: res.data.secretKey || '',
- bucketName: res.data.storageName || '',
- region: res.data.storageRegion || '',
- domain: res.data.domain || '',
- uploadIng: function (progress) {
- that.upload.videoIng = true;
- that.progress = progress;
- }
- }).then(function (res) {
- //成功
- that.$set(that.formData, 'video_link', res.url);
- that.progress = 0;
- that.upload.videoIng = false;
- return that.showMsg('上传成功');
- }).catch(function (err) {
- //失败
- console.info(err);
- return that.showMsg('上传错误请检查您的配置');
- });
- }).catch(function (res) {
- return that.showMsg(res.msg || '获取密钥失败,请检查您的配置');
- });
- })
- }
- });
- function formatDate(time) {
- var date = new Date(time);
- var YY = date.getFullYear() + '-';
- var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
- var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
- var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
- var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
- var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
- return YY + MM + DD;
- }
- </script>
- </body>
- </html>
|