Commit e54783c7 by 前端

Merge branch 'v3.2.0' into 'master'

V3.2.0

See merge request !5
2 parents 29ee6bdc 3c768ce3
...@@ -2246,6 +2246,11 @@ ...@@ -2246,6 +2246,11 @@
"integrity": "sha512-tNEZYz5G/zYunxFm7sfhAxkXEuLj3K6BKwv6ZURlsF6yiUQ65z0Q2wZW9L5cPUl9ocofGvXOdFYbFHp0+6MOig==", "integrity": "sha512-tNEZYz5G/zYunxFm7sfhAxkXEuLj3K6BKwv6ZURlsF6yiUQ65z0Q2wZW9L5cPUl9ocofGvXOdFYbFHp0+6MOig==",
"dev": true "dev": true
}, },
"adler-32": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/adler-32/-/adler-32-1.3.1.tgz",
"integrity": "sha512-ynZ4w/nUUv5rrsR8UUGoe1VC9hZj6V5hU9Qw1HlMDJGEJw5S7TfTErWTjMys6M7vr0YWcPqs3qAr4ss0nDfP+A=="
},
"ajv": { "ajv": {
"version": "6.12.6", "version": "6.12.6",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
...@@ -3282,6 +3287,15 @@ ...@@ -3282,6 +3287,15 @@
"integrity": "sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw==", "integrity": "sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw==",
"dev": true "dev": true
}, },
"cfb": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/cfb/-/cfb-1.2.2.tgz",
"integrity": "sha512-KfdUZsSOw19/ObEWasvBP/Ac4reZvAGauZhs6S/gqNhXhI7cKwvlH7ulj+dOEYnca4bm4SGo8C1bTAQvnTjgQA==",
"requires": {
"adler-32": "~1.3.0",
"crc-32": "~1.2.0"
}
},
"chalk": { "chalk": {
"version": "2.4.2", "version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
...@@ -3635,6 +3649,11 @@ ...@@ -3635,6 +3649,11 @@
"integrity": "sha512-RpAVKQA5T63xEj6/giIbUEtZwJ4UFIc3ZtvEkiaUERylqe8xb5IvqcgOurZLahv93CLKfxcw5YI+DZcUBRyLXA==", "integrity": "sha512-RpAVKQA5T63xEj6/giIbUEtZwJ4UFIc3ZtvEkiaUERylqe8xb5IvqcgOurZLahv93CLKfxcw5YI+DZcUBRyLXA==",
"dev": true "dev": true
}, },
"codepage": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/codepage/-/codepage-1.15.0.tgz",
"integrity": "sha512-3g6NUTPd/YtuuGrhMnOMRjFc+LJw/bnMp3+0r/Wcz3IXUuCosKRJvMphm5+Q+bvTVGcJJuRvVLuYba+WojaFaA=="
},
"collection-visit": { "collection-visit": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/collection-visit/-/collection-visit-1.0.0.tgz", "resolved": "https://registry.npmjs.org/collection-visit/-/collection-visit-1.0.0.tgz",
...@@ -4067,6 +4086,11 @@ ...@@ -4067,6 +4086,11 @@
"parse-json": "^4.0.0" "parse-json": "^4.0.0"
} }
}, },
"crc-32": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz",
"integrity": "sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ=="
},
"create-ecdh": { "create-ecdh": {
"version": "4.0.4", "version": "4.0.4",
"resolved": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.4.tgz", "resolved": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.4.tgz",
...@@ -5981,6 +6005,11 @@ ...@@ -5981,6 +6005,11 @@
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
"dev": true "dev": true
}, },
"frac": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/frac/-/frac-1.1.2.tgz",
"integrity": "sha512-w/XBfkibaTl3YDqASwfDUqkna4Z2p9cFSr1aHDt0WoMTECnRfBOv2WArlZILlqgWlmdIlALXGpM2AOhEk5W3IA=="
},
"fragment-cache": { "fragment-cache": {
"version": "0.2.1", "version": "0.2.1",
"resolved": "https://registry.npmjs.org/fragment-cache/-/fragment-cache-0.2.1.tgz", "resolved": "https://registry.npmjs.org/fragment-cache/-/fragment-cache-0.2.1.tgz",
...@@ -11343,6 +11372,14 @@ ...@@ -11343,6 +11372,14 @@
"integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==", "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==",
"dev": true "dev": true
}, },
"ssf": {
"version": "0.11.2",
"resolved": "https://registry.npmjs.org/ssf/-/ssf-0.11.2.tgz",
"integrity": "sha512-+idbmIXoYET47hH+d7dfm2epdOMUDjqcB4648sTZ+t2JwoyBFL/insLfB/racrDmsKB3diwsDA696pZMieAC5g==",
"requires": {
"frac": "~1.1.2"
}
},
"sshpk": { "sshpk": {
"version": "1.17.0", "version": "1.17.0",
"resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.17.0.tgz", "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.17.0.tgz",
...@@ -13421,6 +13458,16 @@ ...@@ -13421,6 +13458,16 @@
"dayjs": "^1.8.25" "dayjs": "^1.8.25"
} }
}, },
"wmf": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wmf/-/wmf-1.0.2.tgz",
"integrity": "sha512-/p9K7bEh0Dj6WbXg4JG0xvLQmIadrner1bi45VMJTfnbVHsc7yIajZyoSoK60/dtVBs12Fm6WkUI5/3WAVsNMw=="
},
"word": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/word/-/word-0.3.0.tgz",
"integrity": "sha512-OELeY0Q61OXpdUfTp+oweA/vtLVg5VDOXh+3he3PNzLGG/y0oylSOC1xRVj0+l4vQ3tj/bB1HVHv1ocXkQceFA=="
},
"word-wrap": { "word-wrap": {
"version": "1.2.3", "version": "1.2.3",
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
...@@ -13497,6 +13544,20 @@ ...@@ -13497,6 +13544,20 @@
"async-limiter": "~1.0.0" "async-limiter": "~1.0.0"
} }
}, },
"xlsx": {
"version": "0.18.5",
"resolved": "https://registry.npmjs.org/xlsx/-/xlsx-0.18.5.tgz",
"integrity": "sha512-dmg3LCjBPHZnQp5/F/+nnTa+miPJxUXB6vtk42YjBBKayDNagxGEeIdWApkYPOf3Z3pm3k62Knjzp7lMeTEtFQ==",
"requires": {
"adler-32": "~1.3.0",
"cfb": "~1.2.1",
"codepage": "~1.15.0",
"crc-32": "~1.2.1",
"ssf": "~0.11.2",
"wmf": "~1.0.1",
"word": "~0.3.0"
}
},
"xtend": { "xtend": {
"version": "4.0.2", "version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
......
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
"glsx-components": "^1.5.2", "glsx-components": "^1.5.2",
"vue": "^2.6.10", "vue": "^2.6.10",
"vue-router": "^3.1.3", "vue-router": "^3.1.3",
"vuex": "^3.1.2" "vuex": "^3.1.2",
"xlsx": "^0.18.5"
}, },
"devDependencies": { "devDependencies": {
"@vue/cli-plugin-babel": "^4.1.0", "@vue/cli-plugin-babel": "^4.1.0",
......
...@@ -26,9 +26,7 @@ ...@@ -26,9 +26,7 @@
</div> </div>
<img src="./assets/logo.png" alt="" srcset="" /> <img src="./assets/logo.png" alt="" srcset="" />
</div>--> </div>-->
<keep-alive exclude="details">
<router-view /> <router-view />
</keep-alive>
</div> </div>
</template> </template>
......
import { http } from '@/main'
const url = '/rop-scrm-entmicro/router'
// 查询短信营销列
const getMessageList = params => {
params.method = 'entmicro.api.message.findAllByPage'
return http({
url,
method: 'POST',
data: params,
sign: true
})
}
// 保存短信营销配置
const createMessageInfo= params => {
params.method = 'entmicro.api.message.createMessageInfo'
return http({
url,
method: 'POST',
data: params,
sign: true,
returnAll: true
})
}
// 查询短信营销客户列表
const findAllCustomerByPage = params => {
params.method = 'entmicro.api.message.findAllCustomerByPage'
return http({
url,
method: 'POST',
data: params,
sign: true
})
}
// 查询短信营销
const findDetailById = params => {
params.method = 'entmicro.api.message.findDetailById'
return http({
url,
method: 'POST',
data: params,
sign: true,
returnAll: true
})
}
// 删除
const updateMessageInfoStatus = params => {
params.method = 'entmicro.api.message.updateMessageInfoStatus'
return http({
url,
method: 'POST',
data: params,
sign: true
})
}
export default { createMessageInfo,updateMessageInfoStatus,getMessageList, findDetailById, findAllCustomerByPage}
...@@ -18,18 +18,26 @@ html { ...@@ -18,18 +18,26 @@ html {
display: flex; display: flex;
align-items: center; align-items: center;
} }
.outbound .container { .flex-bet {
display: flex;
justify-content: space-between;
}
.flex-top {
display: flex;
align-items: flex-start;
}
.container {
background: #ffffff; background: #ffffff;
padding: 20px; padding: 20px;
} }
.outbound .m-b-20 { .m-b-20 {
margin-bottom: 20px; margin-bottom: 20px;
} }
.word{ .word {
word-wrap: break-all; word-wrap: break-all;
} }
.fwt-4{ .fwt-4 {
font-weight: 400; font-weight: 400;
} }
.font-12 { .font-12 {
...@@ -44,8 +52,8 @@ html { ...@@ -44,8 +52,8 @@ html {
.color3 { .color3 {
color: #333333; color: #333333;
} }
.color58{ .color58 {
color:#5850FF color: #5850ff;
} }
.m-r-4 { .m-r-4 {
margin-right: 4px; margin-right: 4px;
...@@ -61,7 +69,7 @@ html { ...@@ -61,7 +69,7 @@ html {
.outbound.p-t-20 { .outbound.p-t-20 {
padding-top: 20px; padding-top: 20px;
} }
.line-20{ .line-20 {
line-height: 20px; line-height: 20px;
} }
.el-tooltip__popper { .el-tooltip__popper {
...@@ -69,7 +77,7 @@ html { ...@@ -69,7 +77,7 @@ html {
background: #fff; background: #fff;
min-width: 150px; min-width: 150px;
border-radius: 4px; border-radius: 4px;
border: 1px solid #ebeef5!important; border: 1px solid #ebeef5 !important;
padding: 12px; padding: 12px;
z-index: 2000; z-index: 2000;
color: #606266; color: #606266;
...@@ -83,10 +91,18 @@ html { ...@@ -83,10 +91,18 @@ html {
.el-tooltip__popper { .el-tooltip__popper {
max-width: 380px; max-width: 380px;
} }
.el-tooltip__popper[x-placement^="top"] .popper__arrow { .el-tooltip__popper[x-placement^='top'] .popper__arrow {
border-top-color: #ffffff !important; border-top-color: #ffffff !important;
} }
.el-tooltip__popper[x-placement^="top"] .popper__arrow:after { .el-tooltip__popper[x-placement^='top'] .popper__arrow:after {
border-top-color: #ffffff !important; border-top-color: #ffffff !important;
} }
.preview {
width: 412px;
height: 64px;
margin: 0 auto;
}
.pd20 {
padding: 20px;
}
<!-- 搜索 --> <!-- 搜索 -->
<template> <template>
<div class="glsx-combi-form gl-form-page gl-form-min"> <div class="glsx-combi-form gl-form-page gl-form-min">
<el-form :ref="formRef" :inline="true" :model="formObj" :label-width="labelWidth" :rules="formRules" size="mini" class="glsx-combi-form-block"> <el-form :ref="formRef" :inline="inline" :model="formObj" :label-width="labelWidth" :rules="formRules" size="mini" class="glsx-combi-form-block">
<template v-for="(item, index) in formData"> <template v-for="(item, index) in formData">
<el-form-item v-if="!item.isHide" :key="index" :class="{ 'no-label': !item.label, tips: item.tips }" :label="item.label ? item.label + ':' : ''" :prop="item.name"> <el-form-item v-if="!item.isHide" :key="index" :class="{ 'no-label': !item.label, tips: item.tips }" :label="item.label ? item.label + ':' : ''" :prop="item.name">
<slot v-if="item.addHtml" :name="item.addHtml" :scope="item"></slot> <slot v-if="item.addHtml" :name="item.addHtml" :scope="item"></slot>
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
import { rangePickerOptions, rangetimePickerOptions } from './common' import { rangePickerOptions, rangetimePickerOptions } from './common'
export default { export default {
name: 'glsx-combi-form', name: 'glsx-combi-form',
data() { data() {
return { return {
pickerOption: { pickerOption: {
...@@ -97,6 +98,10 @@ export default { ...@@ -97,6 +98,10 @@ export default {
searchSelectObj: { searchSelectObj: {
type: Object, type: Object,
default: () => {} default: () => {}
},
inline: {
type: Boolean,
default: true
} }
}, },
......
...@@ -18,8 +18,8 @@ export const fetchConfig = function (isEnv = true) { ...@@ -18,8 +18,8 @@ export const fetchConfig = function (isEnv = true) {
// Object.assign(request, { timeout }) // Object.assign(request, { timeout })
// return Promise.resolve(cfg) // return Promise.resolve(cfg)
// } // }
// return new Http().get('https://oss-config.dev.glsx.com.cn/mock/62ecda0909756a6f4f85cf9a/outbound/config') return new Http().get('https://oss-config.dev.glsx.com.cn/mock/62ecda0909756a6f4f85cf9a/outbound/config')
return new Http({ request: { timeout: 100000 } }).get('https://oss-config.test.glsx.com.cn/mock/62fe2a36abac6ff6ac239d3c/outbound/config') // return new Http({ request: { timeout: 100000 } }).get('https://oss-config.test.glsx.com.cn/mock/62fe2a36abac6ff6ac239d3c/outbound/config')
} }
export const config = { export const config = {
install(vue, cfg) { install(vue, cfg) {
......
import { Message } from 'element-ui'
let util = {}
util.cloneText = function(message) {
let input = document.createElement('input')
input.value = message
document.body.appendChild(input)
input.select()
input.setSelectionRange(0, input.value.length), document.execCommand('Copy')
document.body.removeChild(input)
Message.success('复制成功')
}
util.getBeforeDate = function(sign = '-') {
let day = new Date()
let month = day.getMonth() + 1
let date = day.getDate()
if (month < 10) month = '0' + month
if (date < 10) date = '0' + date
var s = day.getFullYear() + sign + month + sign + date
return s
}
util.getTimeFomat = function(time, sign = '-') {
let day = new Date(time)
let month = day.getMonth() + 1
let date = day.getDate()
let hour = day.getHours()
let mm = day.getMinutes()
if (month < 10) month = '0' + month
if (date < 10) date = '0' + date
if (hour < 10) hour = '0' + hour
if (mm < 10) mm = '0' + mm
var s = day.getFullYear() + sign + month + sign + date + ' ' + hour + ':' + mm
return s
}
util.getBetweenDate = function(day, num, str = '-') {
var today = new Date(day)
var nowTime = today.getTime()
var ms = 24 * 3600 * 1000 * (num - 1)
today.setTime(parseInt(nowTime - ms))
var oYear = today.getFullYear()
var oMoth = (today.getMonth() + 1).toString()
if (oMoth.length <= 1) oMoth = '0' + oMoth
var oDay = today.getDate().toString()
if (oDay.length <= 1) oDay = '0' + oDay
return oYear + str + oMoth + str + oDay
}
util.getBeforeMonth = function(days) {
let month = new Date().getMonth() + 1
let year = new Date().getFullYear()
let arr = new Array()
for (let i = 0; i < days; i++) {
if (month <= 0) {
year = year - 1
month = month + 12
}
if (month < 10) month = '0' + month
arr[i] = year + '年' + month + '月'
month--
}
return arr
}
util.getPrevMonth = function() {
let month = new Date().getMonth()
let year = new Date().getFullYear()
if (month == 0) {
year = year - 1
month = 12
}
return year + '年' + month + '月'
}
util.getCurrentMonthLast = function(date) {
var endDate = new Date(date)
var month = endDate.getMonth()
var nextMonth = ++month
var nextMonthFirstDay = new Date(endDate.getFullYear(), nextMonth, 1)
var oneDay = 1000 * 60 * 60 * 24
var dateString = new Date(nextMonthFirstDay - oneDay)
return dateString.toLocaleDateString().replace(new RegExp('/', 'g'), '-') //toLocaleDateString() 返回 如:2018/8/31
}
util.openUrl = function(url) {
const link = document.createElement('a')
link.href = url
link.click()
}
util.openTab = function(url) {
const link = document.createElement('a')
link.href = url
link.target = '_blank'
link.rel = 'opener'
link.click()
}
util.isShowBtn = function(value, permissions) {
let isShowStatus = false
const menu = JSON.parse(sessionStorage['SCRM_BASE_MENULIST'])
menuLevel(menu)
function menuLevel(item) {
item.forEach(itm => {
if (value && itm.path == value) {
isShowStatus = true
}
if (
!value &&
itm.path ==
'/' +
location.pathname
.split('/')
.slice(-2)
.join('/') &&
itm.meta &&
itm.meta.permissions.includes(permissions)
) {
isShowStatus = true
}
if (itm.children) {
menuLevel(itm.children)
}
})
}
return isShowStatus
}
util.getArrayIsSubset = (arr2, arr1) => {
return arr2.every(item => {
console.log(arr1.includes(item))
return arr1.includes(item)
})
}
export default util
<template>
<div class="add-wrap" v-loading="loading">
<div class="container">
<div class="title">营销配置</div>
<div style="display: flex">
<div class="gl-form-page">
<el-form ref="configForm" label-width="154px" :model="addForm" :rules="addRules">
<el-form-item label="营销名称:" prop="imName">
<el-input type="text" size="small" placeholder="请输入营销名称" v-model.trim="addForm.imName" maxlength="50"></el-input>
</el-form-item>
<div class="config-form-item el-form-item">
<label class="is-require">营销时间:</label>
<div style="position: relative">
<el-col :span="11">
<el-date-picker type="date" :picker-options="pickerOptions" placeholder="选择日期" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" v-model="addForm.date1" style="width: 100%"></el-date-picker>
</el-col>
<!-- <el-col class="line" :span="1">-</el-col> -->
<el-col :span="11" style="margin-left: 12px">
<el-time-picker placeholder="选择时间" value-format="HH:mm" format="HH:mm" v-model="addForm.date2" style="width: 100%"></el-time-picker>
</el-col>
<div class="el-form-item__error" v-if="isTime">请选择营销时间</div>
</div>
</div>
<div class="config-form-item el-form-item">
<label class="is-require">导入客户:</label>
<div style="position: relative">
<div class="upload-box">
<div class="upload-file-panel flex">
<div class="image-uploader">
<div class="upload-btn">
<i class="el-icon-plus"></i>
上传文件
</div>
<input type="file" style="opacity: 0" ref="file" accept="*" @change="uploadFile" />
</div>
<el-popover placement="bottom" width="455" trigger="hover">
<img src="@/images/table.png" class="preview" />
<span slot="reference" class="download-url">模板预览</span>
</el-popover>
<a class="download-url" href="https://img01.glsx.com.cn/weapp/resource/saas/scrm/xlsx/营销短信客户模板.xlsx">下载模版</a>
</div>
<div class="upload-result" v-if="importName">
<div class="upload-result-input">{{ importName }}</div>
<i class="el-icon-delete" @click="clearFile"></i>
</div>
</div>
<div class="el-form-item__error" v-if="isUplaod">{{ uploadErr }}</div>
</div>
</div>
<div class="config-form-item el-form-item">
<label class="is-require">短信内容:</label>
<div style="position: relative">
<wTextarea ref="textContent" class="textarea" v-model="addForm.messageContext" @updateText="updateText" :style="{ 'min-height': boxHeight + 'px' }"></wTextarea>
<div class="select-panel">
<div @click="handleSelectMessage" class="flex">
<img src="@/images/link.png" class="link" />
<span class="">短链</span>
</div>
</div>
<div class="form-tips">70字內(含70字)计一条,超过70字,按70字/条计费。</div>
<div class="form-tips">提示:当前短信已有{{ addForm.messageContext.length }}字,按{{ content.length }}条短信发送且计费。</div>
<div class="el-form-item__error" v-if="isLink">请填写短信内容</div>
<div class="el-form-item__error" v-if="isLink && count > 1">只允许插入一次短链</div>
</div>
</div>
</el-form>
</div>
<div class="form-image">
<img src="@/images/phone.png" />
<div class="preview-content">
<div class="preview-info">
<div class="preview-text text" v-if="addForm.messageContext">【短信签名】{{ addForm.messageContext }}</div>
</div>
</div>
</div>
</div>
</div>
<GLFooter>
<el-button @click="handleCancel">取消</el-button>
<el-button type="primary" @click="handleSave">提交</el-button>
</GLFooter>
<GLDialog title="提示" @onOk="handleSure" @onCancel="dialogVisible = false" type="warning" content="当前有内容信息未保存,是否继续返回?" :visible.sync="dialogVisible" mode="small"></GLDialog>
<GLDialog title="操作结果" :hasFooter="true" mode="small" :visible.sync="importVisible">
<div class="dialog-body-panel">
<div class="import-result">
<div class="success">
<div class="number">{{ ImportResult.totalCount }}</div>
<div>有效数据</div>
</div>
<div class="fail">
<div class="number">{{ ImportResult.failCount }}</div>
<div>异常数据</div>
</div>
</div>
<div class="import-reason">
<div class="import-tips">数据异常的可能原因:</div>
<div class="import-reason-content">1、存在格式不正确的手机号数据</div>
<div class="import-reason-content">2、存在重复的手机号数据</div>
</div>
</div>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="importVisible = false">取消</el-button>
<el-button size="small" type="primary" @click="handleImport">导出错误数据</el-button>
</span>
</GLDialog>
</div>
</template>
<script>
import wTextarea from './tag-textarea'
import util from '@/utils/util'
import * as XLSX from 'xlsx'
export default {
data() {
return {
addForm: {
imName: '',
sendTime: '',
exportUrl: '',
messageContext: '',
date1: '',
date2: ''
},
uploadErr: '',
content: [],
tabelHeaderModel: ['短链', '短信签名', '商户名称', '手机号', '客户名称'],
addRules: {
imName: [{ required: true, message: '请输入营销名称', trigger: 'blur' }]
},
textValue: '',
importName: '',
loading: false,
isTime: false,
isUplaod: false,
isLink: false,
dialogVisible: false,
importVisible: false,
count: 0,
ImportResult: {},
pickerOptions: {
disabledDate(time) {
return time.getTime() < Date.now() - 24 * 60 * 60 * 1000
}
}
}
},
props: {
boxHeight: {
type: Number,
default: 200
}
},
components: {
wTextarea
},
watch: {
'addForm.messageContext': {
handler: function () {
this.content = []
let str = this.addForm.messageContext
let num = 70
let len = str.length
for (let i = 0; i < len / num; i++) {
let str1 = str.substring(i * num, (i + 1) * num)
this.content.push(str1)
}
}
},
addForm: {
handler() {
this.saveStatus = true
},
deep: true
}
},
methods: {
updateText(html) {
this.addForm.messageContext = html
this.textValue = html
},
handleSelectMessage() {
if (this.$refs.textContent.currentText.indexOf('#短链#') != -1) {
return
}
this.$refs.textContent.addTag('#短链#')
this.addForm.messageContext = this.$refs.textContent.currentText
},
clearFile() {
this.importName = ''
this.addForm.exportUrl = ''
this.$refs.file.value = ''
},
handleSave() {
this.isUplaod = false
this.isTime = false
this.isLink = false
this.count = 0
if (this.addForm.date1 == '' || this.addForm.date2 == '') {
this.isTime = true
return
}
if (this.addForm.exportUrl == '') {
this.isUplaod = true
this.uploadErr = '请上传文件'
return
}
if (this.addForm.messageContext == '') {
this.isLink = true
return
} else {
let array = this.addForm.messageContext.match(/#短链#/g) && this.addForm.messageContext.match(/#短链#/g).length
this.count = array ? array.length : 0
}
if (this.count > 1) {
this.isLink = true
}
if (this.ImportResult.totalCount == 0) {
this.$message.error('导入客户有效数为0,请重新上传')
return
}
this.$refs.configForm.validate(valid => {
if (valid) {
let params = {
imName: this.addForm.imName,
messageContext: this.addForm.messageContext,
exportUrl: this.addForm.exportUrl,
sendTime: this.addForm.date1 + ' ' + this.addForm.date2,
exportName: this.importName
}
this.loading = true
this.$apis.marketing.createMessageInfo(params).then(res => {
if (res.code == 0) {
this.loading = false
this.$router.go(-1)
}
this.$message({
message: res.code == '0' ? '创建成功' : res.message,
type: res.code == '0' ? 'success' : 'error'
})
})
}
})
},
handleSure() {
this.$router.push('/marketing/index')
},
handleCancel() {
if (this.saveStatus) {
this.dialogVisible = true
} else {
this.$router.push('/marketing/index')
}
},
async uploadFile(e) {
const file = e.srcElement.files[0]
let AllImgExt = '.xls|.xlsx'
let extName = file.name.substring(file.name.lastIndexOf('.')).toLowerCase()
if (AllImgExt.indexOf(extName) === -1) {
this.$message.error('上传格式不正确')
return false
}
const header = await this.compareHeader(file)
if (util.getArrayIsSubset(header, this.tabelHeaderModel)) {
const reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = event => {
const imgFile = event.target.result
const arrBase64 = imgFile.split(',')
const fileUrl = file.name.split('.')[1] + '@' + arrBase64[1]
this.$apis.common.pictureUpload({ file: fileUrl }).then(res => {
this.importName = file.name
this.addForm.exportUrl = res
this.isUplaod = false
this.$refs.file.value = ''
this.uploadErr = ''
this.handleSaveImport()
})
}
} else {
this.importName = ''
this.isUplaod = true
this.uploadErr = '文件格式错误,请更换文件'
this.$refs.file.value = ''
this.addForm.exportUrl = ''
}
},
compareHeader(file) {
return new Promise(resolve => {
const reader = new FileReader()
reader.onload = event => {
/* 解析数据 */
const bstr = event.target.result
const wb = XLSX.read(bstr, { type: 'binary' })
/* 获取文件的第一个工作表(WorkSheet) */
const wsname = wb.SheetNames[0]
const ws = wb.Sheets[wsname]
if (!ws['!ref']) {
this.$message.error('格式错误')
return
}
const data = this.getHeaderRow(ws)
resolve(data)
}
reader.readAsBinaryString(file)
})
},
getHeaderRow(sheet) {
const headers = []
/* sheet['!ref']表示所有单元格的范围,例如从A1到F8则记录为 A1:F8*/
const range = XLSX.utils.decode_range(sheet['!ref'])
let C,
R = range.s.r /* 从第一行开始 */
/* 按列进行数据遍历 */
for (C = range.s.c; C <= range.e.c; ++C) {
/* 查找第一行中的单元格 */
const cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })]
let hdr = 'UNKNOWN ' + C // <-- 进行默认值设置
if (cell && cell.t) hdr = XLSX.utils.format_cell(cell)
if (!hdr.includes('UNKNOWN')) {
headers.push(hdr)
}
}
return headers
},
handleSaveImport() {
let params = {
exportUrl: this.addForm.exportUrl
}
this.$apis.marketing.createMessageInfo(params).then(res => {
if (res.code == 0) {
this.importVisible = true
this.ImportResult = res.data
} else {
this.$message({
message: res.message,
type: 'error'
})
this.clearFile()
}
})
},
handleImport() {
if (this.ImportResult.errorUrl) {
util.openUrl(this.ImportResult.errorUrl.replace(/https?:/, ''))
} else {
this.$message({
message: '暂无错误数据',
type: 'error'
})
}
}
}
}
</script>
<style lang="scss" scoped>
.container {
background: #ffffff;
margin-bottom: 16px;
padding: 0;
.title {
height: 56px;
line-height: 56px;
border-bottom: 1px solid #e5e5e5;
padding-left: 20px;
box-sizing: border-box;
}
.gl-form-page {
flex: 1;
padding: 20px;
.config-form-item {
display: flex;
margin-top: 20px;
/deep/.el-form-item__content {
width: 460px;
}
/deep/.el-input--prefix .el-input__inner {
line-height: 32px;
height: 32px;
}
}
/deep/.el-input__prefix {
line-height: 32px;
.el-input__icon {
line-height: 32px;
}
}
label {
font-size: 14px;
text-align: right;
color: #666;
width: 154px;
// margin-right: 12px;
height: 36px;
line-height: 36px;
img {
width: 14px;
height: 14px;
vertical-align: middle;
margin-left: 5px;
}
&.is-require {
&::before {
content: '*';
color: #f56c6c;
margin-right: 4px;
}
}
}
.line {
color: #fff;
}
.download-url {
margin-left: 11px;
font-size: 12px;
font-weight: 400;
color: #5850ff;
line-height: 17px;
}
.link {
width: 18px;
height: 18px;
margin-right: 4px;
}
.upload-box {
// margin-bottom: 10px;
.upload-btn {
background: #ffffff;
border: 1px solid #e5e5e5;
border-radius: 3px;
text-align: center;
font-weight: 400;
font-size: 14px;
color: #666666;
box-sizing: border-box;
padding: 6px 17px;
line-height: 20px;
}
.upload-result {
display: flex;
align-items: center;
margin-top: 6px;
&-input {
width: 320px;
height: 26px;
background: #f5f7fa;
border-radius: 4px;
font-size: 14px;
padding-left: 12px;
color: #333333;
line-height: 26px;
}
> i {
cursor: pointer;
color: #c6c6c6;
font-size: 14px;
margin-left: 10px;
}
}
.upload-tips {
margin-top: 6px;
font-size: 14px;
font-weight: 400;
color: #999999;
line-height: 20px;
}
}
.textarea {
width: 580px !important;
}
.select-panel {
padding-left: 20px;
background: #fafbfe;
display: flex;
font-size: 14px;
font-weight: 400;
color: #666666;
line-height: 40px;
border: 1px solid #e5e5e5;
width: 580px !important;
border-top: 0px;
box-sizing: border-box;
border-radius: 0 0 4px 4px;
cursor: pointer;
}
.image-uploader {
display: inline-block;
width: 120px;
position: relative;
input {
cursor: pointer;
position: absolute;
top: 0px;
width: 100%;
height: 100%;
font-size: 0px;
}
/deep/ {
.el-upload-list {
display: none;
}
}
}
.form-tips {
font-size: 12px;
color: #999999;
line-height: 20px;
margin-top: 4px;
white-space: nowrap;
}
}
.form-image {
width: 280px;
height: 546px;
margin: 20px 80px 20px 0;
position: relative;
.preview-content {
position: absolute;
width: 250px;
height: 320px;
overflow-y: auto;
top: 125px;
left: 50px;
.preview-text {
padding: 10px;
position: relative;
width: 160px;
color: #333;
background-color: #f4f4f4;
border-radius: 4px;
word-wrap: break-word;
margin-bottom: 10px;
line-height: 15px;
}
}
img {
width: 100%;
height: auto;
}
}
}
.dialog-body-panel {
.import-result {
font-size: 14px;
color: #333333;
line-height: 22px;
display: flex;
align-items: center;
.success {
text-align: center;
flex: 1;
border-right: 1px solid #e7e7e7;
.number {
color: #2cca74;
font-size: 26px;
font-weight: 600;
margin-bottom: 4px;
}
}
.fail {
text-align: center;
flex: 1;
.number {
color: #eb4e4e;
font-size: 26px;
font-weight: 600;
margin-bottom: 4px;
}
}
}
.import-reason {
height: 80px;
background: #f5f5f5;
padding: 8px 16px;
box-sizing: border-box;
margin-top: 16px;
.import-tips {
font-size: 14px;
font-weight: 400;
color: #666666;
line-height: 20px;
margin-bottom: 4px;
}
&-content {
font-size: 14px;
font-weight: 400;
color: #333333;
line-height: 20px;
}
}
}
</style>
\ No newline at end of file \ No newline at end of file
<template>
<div class="client">
<div class="container">
<GLCombiForm :rowNumber="1" ref="formSearch" :formObj="searchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
<!-- 表格区域 开始 -->
<GLTable ref="clientRef" :getListApi="getListApi" :noDataImg="url" :searchForm="searchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
<template slot="delFlag" slot-scope="scope">
<div :class="['task_icon', scope.scope.delFlag == 0 ? 'task_icon1' : 'task_icon2']">{{ scope.scope.delFlag == 0 ? '待发送' : '已发送' }}</div>
</template>
<div class="table-btns" slot="auth-button" slot-scope="scope">
<el-button type="text" @click="handleContent(scope.scope)">短信内容</el-button>
</div>
</GLTable>
</div>
<!-- 外呼短信 -->
<GLDialog mode="small" title="短信内容" :visible.sync="messageVisible" cancelText="取消" okText="确定" @onCancel="messageVisible = false" @onOk="handleMessageConfirm" >
<div class="market-note">{{ messageContext }}</div>
</GLDialog>
</div>
</template>
<script>
import url from '@/assets/empty.png'
export default {
data() {
return {
messageVisible: false,
messageContext: '',
url: url,
searchForm: {
phone: '',
delFlag: '',
merchantName: '',
imId: ''
},
// 搜索
searchFormData: [
{
label: '手机号',
name: 'phone ',
type: 'input'
},
{
label: '状态',
name: 'delFlag',
type: 'select',
optionList: [
{ text: '待发送', id: 0 },
{ text: '已发送', id: 1 }
],
optionId: 'id',
optionLabel: 'text'
},
{
label: '所属门店',
name: 'merchantName',
type: 'input'
}
],
getListApi: this.$apis.marketing.findAllCustomerByPage,
tableParams: {
listName: 'data',
tableOption: true,
tableColumns: [
{
label: '手机号',
prop: 'phone'
},
{
label: '客户姓名',
prop: 'customerName'
},
{
label: '所属门店',
prop: 'merchantName'
},
{
label: '状态',
prop: 'delFlag',
addHtml: 'delFlag'
},
{
label: '发送时间',
prop: 'sendTime'
}
]
},
pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'count' }
}
},
props: {
imId: {
type: String,
default: ''
}
},
methods: {
handleContent(data) {
this.messageContext = data.messageContext
this.messageVisible = true
},
handleMessageConfirm() {
this.messageVisible = false
},
getParams() {
var params = JSON.parse(JSON.stringify(this.searchForm))
params.imId = this.imId
return params
},
beforeSearchFn() {
return new Promise(resolve => {
this.searchForm = this.getParams()
resolve()
})
},
setTableFinishFun() {
//接收到的数据为空
this.$refs.clientRef.data.length ? (this.$refs.clientRef.tableHeightValues = '') : this.$refs.clientRef.setTableHeightFun()
},
handleSearch() {
console.log(111)
this.$refs.clientRef.refreshTable()
},
handleReset() {
this.searchForm = {
phone: '',
delFlag: '',
merchantName: '',
imId: ''
}
this.handleSearch()
}
}
}
</script>
<style lang="scss" scoped>
.client {
margin: 16px 0;
.task_icon {
position: relative;
&::after {
content: '';
position: absolute;
top: 4px;
left: -10px;
width: 6px;
height: 6px;
border-radius: 4px;
}
&.task_icon1 {
&::after {
background: #fdb757;
}
}
&.task_icon2 {
&::after {
background: #2cca74;
}
}
}
.market-note {
font-weight: 400;
font-size: 16px;
color: #333333;
line-height: 24px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
// text-align: center;
width: 448px;
white-space: wrap;
}
}
</style>
\ No newline at end of file \ No newline at end of file
<template>
<div class="detail-wrap">
<GLTabs v-model="activeName" :tabPaneList="tabPaneList" @tab-click="handleClick"></GLTabs>
<div class="container" v-if="activeName == 'first'">
<div class="title">营销配置</div>
<div class="flex-bet pd20">
<div class="detail-content">
<template v-for="(item, index) in configList">
<div class="flex-top line-text" :key="index">
<div class="type-text">{{ item.text }}</div>
<tempalte v-if="item.key == 'exportName'">
<a class="type-value exportName" @click="download(detailData)">{{ detailData[item.key] }}</a>
</tempalte>
<div v-else class="type-value">{{ detailData[item.key] ? detailData[item.key] : '--' }}</div>
</div>
</template>
</div>
<div class="form-image">
<img src="@/images/phone.png" />
<div class="preview-content">
<div class="preview-info">
<div class="preview-text text" :key="index">{{ detailData.messageContext }}</div>
</div>
</div>
</div>
</div>
</div>
<template v-else>
<client :imId="id"></client>
</template>
<GLFooter>
<el-button @click="handleCancel" type="primary">返回</el-button>
</GLFooter>
</div>
</template>
<script>
import client from './client.vue'
export default {
components: {
client
},
data() {
return {
id: this.$route.query.id ? this.$route.query.id : 0,
activeName: 'first',
tabPaneList: [
{
label: '短信配置',
name: 'first'
},
{
label: '客户列表',
name: 'second'
}
],
detailData: '',
content: [],
configList: [
{
text: '营销名称:',
key: 'imName'
},
{
text: '营销时间:',
key: 'sendTime'
},
{
text: '导入客户:',
key: 'exportName'
},
{
text: '有效数据:',
key: 'customerCount'
},
{
text: '营销内容:',
key: 'messageContext'
}
]
}
},
created() {
this.congifDetails()
},
methods: {
download(data) {
this.getBlob(data.exportUrl).then(blob => {
this.saveAs(blob, data.exportName)
})
},
getBlob(url) {
return new Promise(resolve => {
const xhr = new XMLHttpRequest()
xhr.open('GET', url, true)
xhr.responseType = 'blob'
xhr.onload = () => {
if (xhr.status === 200) {
resolve(xhr.response)
}
}
xhr.send()
})
},
saveAs(blob, filename) {
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, filename)
} else {
const link = document.createElement('a')
const body = document.querySelector('body')
let binaryData = []
binaryData.push(blob)
link.href = window.URL.createObjectURL(new Blob(binaryData))
link.download = filename
// fix Firefox
link.style.display = 'none'
body.appendChild(link)
link.click()
body.removeChild(link)
window.URL.revokeObjectURL(link.href)
}
},
congifDetails() {
let params = {
id: this.id
}
this.$apis.marketing.findDetailById(params).then(res => {
if (res.code == 0) this.detailData = res.data
})
},
handleCancel() {
this.$router.go(-1)
},
handleClick() {
console.log(this.activeName)
}
}
}
</script>
<style lang="scss" scoped>
.container {
background: #ffffff;
margin: 16px 0;
padding: 0;
.title {
height: 56px;
line-height: 56px;
border-bottom: 1px solid #e5e5e5;
padding-left: 20px;
box-sizing: border-box;
}
.detail-content {
flex: 1;
.line-text {
margin-left: 84px;
margin-bottom: 22px;
height: 20px;
font-weight: 400;
font-size: 14px;
color: #333333;
}
.type-text {
width: 70px;
text-align: right;
line-height: 20px;
}
.type-value {
max-width: 576px;
line-height: 20px;
}
.exportName {
text-decoration: underline;
color: #5850ff;
cursor: pointer;
}
}
.form-image {
width: 280px;
height: 546px;
margin-right: 80px;
position: relative;
.preview-content {
position: absolute;
width: 250px;
height: 320px;
overflow-y: auto;
top: 125px;
left: 50px;
.preview-text {
padding: 10px;
position: relative;
width: 160px;
color: #333;
background-color: #f4f4f4;
border-radius: 4px;
word-wrap: break-word;
margin-bottom: 10px;
}
}
img {
width: 100%;
height: auto;
}
}
}
</style>
\ No newline at end of file \ No newline at end of file
<template>
<div class="marketing">
<div class="flex head">
<el-button type="primary" size="small" icon="el-icon-plus" @click="handleAdd">新增营销</el-button>
<div class="head-info flex">
<p>结合门店营销活动,指定客户创建智能营销,提高活动转化率</p>
<el-popover placement="top" width="560" trigger="hover" content="通过导入的客户,门店可通过智能外呼及智能短信,结合营销活动的需要向离店用户进行智能营销,可实现标准、高效的营销同时实现用户线上化。">
<img src="@/images/question.png" slot="reference" class="count-item-question" />
</el-popover>
</div>
</div>
<div class="container">
<GLCombiForm :rowNumber="1" ref="formSearch" :formObj="tableSearchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
<!-- 表格区域 开始 -->
<GLTable ref="marketingRef" :getListApi="getListApi" :noDataImg="url" :searchForm="searchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
<template slot="imStatus" slot-scope="scope">
<div :class="['task_icon', scope.scope.imStatus == 1 ? 'task_icon1' : 'task_icon2']">{{ scope.scope.imStatus == 1 ? '待处理' : scope.scope.imStatus == 2 ? '已完成' : '删除' }}</div>
</template>
<div class="table-btns" slot="auth-button" slot-scope="scope">
<el-button type="text" @click="handleDetails(scope.scope)">详情</el-button>
<el-button type="text" @click="handleDelete(scope.scope)">删除</el-button>
</div>
</GLTable>
</div>
</div>
</template>
<script>
import url from '@/assets/empty.png'
export default {
data() {
return {
url: url,
tableSearchForm: {
imName: '',
imStatus: '',
createDate: []
},
searchForm: {},
// 搜索
searchFormData: [
{
label: '创建时间',
name: 'createDate',
type: 'datePicker',
isClear: true
},
{
label: '状态',
name: 'imStatus',
type: 'select',
optionList: [
{ text: '全部', id: '' },
{ text: '待处理', id: 1 },
{ text: '已完成', id: 2 }
],
optionId: 'id',
optionLabel: 'text'
},
{
label: '营销名称',
name: 'imName',
type: 'input'
}
],
getListApi: this.$apis.marketing.getMessageList,
tableParams: {
listName: 'data',
tableOption: true,
tableColumns: [
{
label: '营销名称',
prop: 'imName',
line:1,
width:350
},
{
label: '营销客户数',
prop: 'customerCount'
},
{
label: '状态',
prop: 'imStatus',
addHtml: 'imStatus'
},
{
label: '创建时间',
prop: 'sendTime'
},
{
label: '创建人',
prop: 'createdName'
}
]
},
pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'count' }
}
},
methods: {
handleAdd() {
this.$router.push({
path: '/marketing/add'
})
},
handleDetails(data) {
this.$router.push({
path: '/marketing/details',
query: {
id: data.id
}
})
},
handleDelete(data) {
this.$confirm('删除后数据将无法恢复,是否确认删除?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(() => {
this.$apis.marketing.updateMessageInfoStatus({ id: data.id, imStatus: 3 }).then(res => {
if (res) {
this.$message({
type: 'success',
message: '删除成功!'
})
}
this.handleSearch()
})
})
.catch(() => {})
},
getParams() {
var params = JSON.parse(JSON.stringify(this.tableSearchForm))
if (this.tableSearchForm.createDate.length) {
params.startTime = new Date(this.tableSearchForm.createDate[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
params.endTime = new Date(this.tableSearchForm.createDate[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
}
params.taskStatus = this.currentIndex
return params
},
beforeSearchFn() {
return new Promise(resolve => {
this.searchForm = this.getParams()
delete this.searchForm.createDate
resolve()
})
},
setTableFinishFun() {
//接收到的数据为空
this.$refs.marketingRef.data.length ? (this.$refs.marketingRef.tableHeightValues = '') : this.$refs.marketingRef.setTableHeightFun()
},
handleSearch() {
this.$refs.marketingRef.refreshTable()
},
handleReset() {
this.tableSearchForm = {
imName: '',
imStatus: '',
createDate: []
}
this.searchForm = {
imName: '',
imStatus: '',
startTime: '',
endTime: ''
}
this.handleSearch()
}
}
}
</script>
<style lang="scss" scoped>
.marketing {
.head {
margin-bottom: 16px;
}
.head-info {
font-weight: 400;
font-size: 14px;
color: #666666;
p {
margin: 0 4px 0 12px;
line-height: 16px;
}
.count-item-question {
width: 14px;
height: 14px;
display: inline-block;
}
}
.task_icon {
position: relative;
&::after {
content: '';
position: absolute;
top: 4px;
left: -10px;
width: 6px;
height: 6px;
border-radius: 4px;
}
&.task_icon1 {
&::after {
background: #fdb757;
}
}
&.task_icon2 {
&::after {
background: #2cca74;
}
}
}
}
</style>
\ No newline at end of file \ No newline at end of file
<template>
<div class="w-textarea" ref="wTextarea" v-bind="$attr">
<div contenteditable="true" class="w-textarea_input" ref="wTextareaContent" :id="contentId" @keydown="textareaKeydown($event)" @click="inputClick($event)" @focus="onFocus" @blur="onBlur" @keydown.delete="handleDelete($event)" @input="handleInput($event.target)"></div>
</div>
</template>
<script>
export default {
name: 'wTextarea',
data() {
return {
// 记录currentText以计算长度
currentText: this.value,
// 为input区域生成随机id,当在页面上有多个组件时,用于监听光标的变化
contentId: `content${this.getGuid()}`,
// 输入的时候锁定,禁止更新innerHTML
isLocked: false,
isInsert: false,
// 记录当前选中tag的ID
currentTagId: null,
// 当前光标位置
savedRange: {}
}
},
props: {
value: {
type: String,
default: ''
},
tag: {
// 自定义模版标签的标签名
type: String,
// 默认使用wise作为标签名,并添加了默认样式
// 当使用其他标签名的时候,需要另写标签样式
default: 'wise'
},
tools: {
// 自定义扩展功能:超链接'link',模版标签'tag'
type: Array,
default() {
return [
{ type: 'link', text: '添加超链接' },
{ type: 'tag', text: '添加模版标签' }
]
}
},
maxlength: {
// 最大输入长度
type: [String, Number],
default: ''
}
},
computed: {
count() {
// 字符长度记数
let num = this.maxlength - this.currentText.length
let text = num < 0 ? `已超出${Math.abs(num)}个字符` : `还可以输入${num}个字符`
return { num, text }
}
},
mounted() {
// 初始化数据
this.currentText && (this.$refs.wTextareaContent.innerHTML = this.currentText)
// 创建模版标签的style
this.createStyle()
// 每次光标变化的时候,保存 range
document.addEventListener('selectionchange', this.selectHandler)
},
beforeDestroy() {
// 卸载事件
document.removeEventListener('selectionchange', this.selectHandler)
},
methods: {
updateData(text) {
this.$emit('input', text)
},
createStyle() {
// 为自定义的模版标签添加样式,使之不可编辑
let style = document.createElement('style')
style.innerHTML = `.w-textarea ${this.tag} {
cursor: default;
-webkit-user-modify: read-only !important;
}`
this.$refs.wTextarea.appendChild(style)
},
closeModal() {
this.form.text = ''
this.showModal = false
},
openTagDialog(type) {
// if (addLink)
// 将事件抛给父组件处理
// 处理后需要调用 addTag() 或者 addLink() 将内容传回来
this.$emit('add', type)
},
textareaKeydown(event) {
if (event.keyCode == 13) {
this.insertHtml('<br>')
let nn = document.createElement('br')
document.querySelector('.w-textarea_input').appendChild(nn)
return false
}
},
/*换行*/
insertHtml(html) {
var sel, range
if (window.getSelection) {
// IE9 或 非IE浏览器
sel = window.getSelection()
if (sel.getRangeAt && sel.rangeCount) {
range = sel.getRangeAt(0)
range.deleteContents()
// Range.createContextualFragment() would be useful here but is
// non-standard and not supported in all browsers (IE9, for one)
var el = document.createElement('div')
el.innerHTML = html
var frag = document.createDocumentFragment(),
node,
lastNode
while ((node = el.firstChild)) {
lastNode = frag.appendChild(node)
}
range.insertNode(frag)
// Preserve the selection
if (lastNode) {
range = range.cloneRange()
range.setStartAfter(lastNode)
range.collapse(true)
sel.removeAllRanges()
sel.addRange(range)
}
}
} else if (document.selection && document.selection.type != 'Control') {
// IE < 9
document.selection.createRange().pasteHTML(html)
}
const htm = document.querySelector('.w-textarea_input').innerHTML
this.subText(htm)
},
addTag(text) {
// 创建模版标签
let node = document.createElement(this.tag)
if (navigator.userAgent.indexOf('Firefox') > 0) {
node.setAttribute('contenteditable', 'false')
}
node.innerText = text
// 添加id便于删除
node.id = this.getGuid()
this.insertNode(node)
},
addNode() {
let target = this.$refs.wTextareaContent
this.updateData(target.innerHTML)
},
addLink(text, url) {
// 创建a标签
let node = document.createElement('a')
node.innerText = text
node.href = url
node.target = 'blank'
this.insertNode(node)
},
addImg(url) {
// 创建a标签
let node = document.createElement('img')
node.src = url
// node.setAttribute('ondragstart', 'return false;')
this.insertNode(node)
},
onFocus() {
this.isLocked = true
this.isInsert = true
},
onBlur() {
this.isLocked = false
},
insertNode(node) {
// 在内容中插入标签
// 删掉选中的内容(如有)
if (this.savedRange.startContainer) {
this.insertNodeFirst(node)
} else {
document.querySelector('.w-textarea_input').focus()
setTimeout(() => {
this.insertNodeFirst(node)
document.querySelector('.w-textarea_input').blur()
}, 100)
}
},
subText(htm) {
const cutImg = htm
.replace(/<wise.+?>(.+?)(?:<\/wise>)/g, '$1')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&amp;/g, '&')
.replace(/(\n|\s|&nbsp;)/g, '')
.replace(/<br>/g, '\n')
.replace(/<span>([\s\S]*?)<\/span>/g, '$1')
.replace(/<div>([\s\S]*?)<\/div>/g, '$1')
this.currentText = cutImg
this.$emit('updateText', this.currentText)
},
insertNodeFirst(node) {
this.savedRange.deleteContents()
// 插入链接
if (this.isInsert) {
this.savedRange.insertNode(node)
} else {
document.querySelector('.w-textarea_input').appendChild(node)
}
if (navigator.userAgent.indexOf('Chrome') != -1) {
this.savedRange.insertNode(document.createElement('span'))
}
this.isInsert = false
// 更新双向绑定数据
let target = this.$refs.wTextareaContent
if (navigator.userAgent.indexOf('Firefox') > 0 || navigator.userAgent.indexOf('QQBrowser') > 0) {
this.updateData(target.innerHTML + '&nbsp;')
} else {
this.updateData(target.innerHTML)
}
let htm = target.innerHTML
this.subText(htm)
},
placeCaretAtEnd(el) {
//传入光标要去的jq节点对象
el.focus()
if (typeof window.getSelection != 'undefined' && typeof document.createRange != 'undefined') {
var range = document.createRange()
range.selectNodeContents(el)
range.collapse(false)
var sel = window.getSelection()
sel.removeAllRanges()
sel.addRange(range)
} else if (typeof document.body.createTextRange != 'undefined') {
var textRange = document.body.createTextRange()
textRange.moveToElementText(el)
textRange.collapse(false)
textRange.select()
}
},
handleInput(target) {
// 即时更新数据
this.updateData(target.innerHTML)
let htm = target.innerHTML
this.subText(htm)
},
handleDelete(e) {
// 监听“删除”事件
if (this.currentTagId) {
// 若已选中模版标签,直接删除dom节点
let t = document.getElementById(this.currentTagId)
this.$refs.wTextareaContent.removeChild(t)
this.currentTagId = null
// 阻止浏览器默认的删除事件,并手动更新数据
e.preventDefault()
this.handleInput(e.target)
}
},
inputClick(e) {
// 监听点击事件
this.isLocked = true
const TAG_NAME = e.target.nodeName
if (TAG_NAME === this.tag.toUpperCase()) {
// 点击模版标签时,记录id
this.currentTagId = e.target.id
e.target.className = 'active'
} else if (this.currentTagId) {
// 清空active样式
let target = document.getElementById(this.currentTagId)
target.className = ''
this.currentTagId = null
} else {
this.currentTagId = null
}
},
getGuid() {
// 生成随机ID
return 1
// return `r${new Date().getTime()}d${Math.ceil(Math.random() * 1000)}`
},
selectHandler() {
// 监听选定文本的变动
let sel = window.getSelection()
let range = sel.rangeCount > 0 ? sel.getRangeAt(0) : null
if (range && range.commonAncestorContainer.ownerDocument.activeElement.id === this.contentId) {
this.savedRange = range
}
}
},
watch: {
value(val) {
// 非锁定状态下,实时更新innerHTML
if (!this.isLocked) {
this.$refs.wTextareaContent.innerHTML = val
}
}
}
}
</script>
<style lang="scss">
.w-textarea {
wise {
user-select: none;
border-radius: 2px;
background-color: #fff;
font-size: 14px;
color: #5850ff;
line-height: 20px;
padding: 0px;
margin: 0 2px;
color: #26a2ff;
// padding: 0 1px;
white-space: nowrap;
cursor: default;
-webkit-user-modify: read-only !important;
}
img {
width: 18px;
height: 18px;
-webkit-user-select: none;
cursor: default;
pointer-events: none;
vertical-align: middle;
}
.active {
background: #dcdfe6;
}
}
</style>
<style lang="scss" scoped>
$borderColor: #e5e5e5;
$bgColor: #f5f7fa;
$textColor: #666;
.w-textarea {
width: 100%;
box-sizing: border-box;
border-top-right-radius: 4px;
border-top-left-radius: 4px;
border: 1px solid $borderColor;
position: relative;
overflow-y: auto;
&_input {
width: 100%;
height: 200px;
min-height: 100px;
box-sizing: border-box;
padding: 10px;
line-height: 1.5;
word-break: break-word;
// 允许编辑,禁止富文本
-webkit-user-modify: read-write-plaintext-only !important;
&:focus {
outline: none;
}
}
&_tools {
padding: 0 10px;
height: 40px;
line-height: 40px;
border-top: 1px solid $borderColor;
background-color: $bgColor;
color: $textColor;
font-size: 12px;
&__item {
display: inline-block;
line-height: 1;
padding: 5px 8px;
margin-right: 8px;
color: $textColor;
cursor: pointer;
border: 1px solid $borderColor;
border-radius: 4px;
background: #fff;
transition: all 0.3s;
&:hover {
background: $bgColor;
opacity: 0.7;
}
&:focus {
outline: none;
}
}
&__text {
display: inline-block;
line-height: 40px;
padding: 0 8px;
float: right;
color: $textColor;
cursor: default;
transition: all 0.3s;
&:hover {
opacity: 1;
}
&.__danger {
color: red;
}
}
}
}
</style>
...@@ -9,7 +9,7 @@ const cdn = { ...@@ -9,7 +9,7 @@ const cdn = {
js: [`${CDN_DOMAIN}ajax/libs/vue/2.6.11/vue.min.js`, `${CDN_DOMAIN}ajax/libs/vue-router/3.2.0/vue-router.min.js`, `${CDN_DOMAIN}ajax/libs/element-ui/2.11.1/index.js`, `${CDN_DOMAIN}ajax/libs/vuex/3.6.2/vuex.min.js`, `${CDN_DOMAIN}ajax/libs/echarts/5.1.2/echarts.min.js`] js: [`${CDN_DOMAIN}ajax/libs/vue/2.6.11/vue.min.js`, `${CDN_DOMAIN}ajax/libs/vue-router/3.2.0/vue-router.min.js`, `${CDN_DOMAIN}ajax/libs/element-ui/2.11.1/index.js`, `${CDN_DOMAIN}ajax/libs/vuex/3.6.2/vuex.min.js`, `${CDN_DOMAIN}ajax/libs/echarts/5.1.2/echarts.min.js`]
} }
module.exports = { module.exports = {
outputDir: `../dist/${packageName}`, outputDir: `dist`,
publicPath, publicPath,
assetsDir: 'static', assetsDir: 'static',
productionSourceMap: false, productionSourceMap: false,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!