| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>活动</title>
- <meta name="viewport"
- content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
- <link href="css/mui.css" rel="stylesheet" />
- <link href="css/mui.picker.css" rel="stylesheet" />
- <link href="css/mui.poppicker.css" rel="stylesheet" />
- <script src="js/mui.js"></script>
- <script src="js/mui.picker.js"></script>
- <script src="js/mui.poppicker.js"></script>
- <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
- <!-- <script src="js/vconsole.min.js"></script>
- <script>
- var vConsole = new window.VConsole();
- </script> -->
- <script type="text/javascript">
- mui.init()
- (function flexible (window, document) {
- let docEl = document.documentElement
- let dpr = window.devicePixelRatio || 1
- // adjust body font size
- function setBodyFontSize () {
- if (document.body) {
- document.body.style.fontSize = (12 * dpr) + 'px'
- } else {
- document.addEventListener('DOMContentLoaded', setBodyFontSize)
- }
- }
- setBodyFontSize()
- // set 1rem = viewWidth / 10
- function setRemUnit () {
- let rem = docEl.clientWidth / 375
- docEl.style.fontSize = rem + 'px'
- }
- setRemUnit()
- // reset rem unit on page resize
- window.addEventListener('resize', setRemUnit)
- window.addEventListener('pageshow', function(e) {
- if (e.persisted) {
- setRemUnit()
- }
- })
- // detect 0.5px supports
- if (dpr >= 2) {
- let fakeBody = document.createElement('body')
- let testElement = document.createElement('div')
- testElement.style.border = '.5px solid transparent'
- fakeBody.appendChild(testElement)
- docEl.appendChild(fakeBody)
- if (testElement.offsetHeight === 1) {
- docEl.classList.add('hairlines')
- }
- docEl.removeChild(fakeBody)
- }
- }(window, document));
- (function() {
- if (typeof WeixinJSBridge === 'object' && typeof WeixinJSBridge.invoke === 'function') {
- handleFontSize()
- } else {
- if (document.addEventListener) {
- document.addEventListener('WeixinJSBridgeReady', handleFontSize, false)
- } else if (document.attachEvent) {
- document.attachEvent('onWeixinJSBridgeReady', handleFontSize)
- }
- }
- function handleFontSize () {
- // 设置网页字体为默认大小
- WeixinJSBridge.invoke('setFontSizeCallback', { 'fontSize': 0 })
- // 重写设置网页字体大小的事件
- WeixinJSBridge.on('menu:setfont', function() {
- WeixinJSBridge.invoke('setFontSizeCallback', { 'fontSize': 0 })
- })
- }
- })()
- </script>
- </head>
- <style type="text/css">
- body {
- margin: 0;
- background: #FFFFFF;
- }
- #collectPage,
- #qrcode {
- display: none;
- }
- .mui-input-group {
- padding-top: 15px;
- }
- .mui-input-group:before {
- background: none;
- }
- .mui-input-group:after {
- background: none;
- }
- .mui-input-group .mui-input-row:after {
- background: none;
- }
- .mui-input-group .mui-input-row {
- height: 60px;
- }
- ::-webkit-input-placeholder {
- /* Chrome/Opera/Safari */
- font-weight: 400;
- font-size: 14px;
- color: #CCCCCC;
- float: right;
- }
- ::-moz-placeholder {
- /* Firefox 19+ */
- font-weight: 400;
- font-size: 14px;
- color: #CCCCCC;
- float: right;
- }
- :-ms-input-placeholder {
- /* IE 10+ */
- font-weight: 400;
- font-size: 14px;
- color: #CCCCCC;
- float: right;
- }
- :-moz-placeholder {
- /* Firefox 18- */
- font-weight: 400;
- font-size: 14px;
- color: #CCCCCC;
- float: right;
- }
- .mui-input-clear {
- font-weight: 500;
- font-size: 14px;
- color: #222222;
- text-align: right;
- padding: 10px 0;
- padding-right: 30px !important;
- }
- .mui-input-row label {
- font-weight: 500;
- font-size: 14px;
- color: #666666;
- }
- .dialog {
- position: fixed;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- background-color: rgba(0, 0, 0, 0.5);
- /* 半透明黑色 */
- z-index: 1000;
- /* 确保遮罩层在顶部 */
- transition: opacity 0.5s ease;
- /* 可选:添加透明度过渡效果 */
- display: none;
- }
- .mui-poppicker {
- z-index: 1002 !important;
- }
- .bg_content {
- height: calc(100vh + 44rem);
- width: 100vw;
- background: url('./img/blessings.png');
- background-size: cover;
- margin-top: -44rem;
- }
- .show_box {
- position: absolute;
- top: 154rem;
- /* background: #FFFFFF; */
- left: 15rem;
- right: 15rem;
- height: 290rem;
- }
- .show_box .show_item {
- width: 20rem;
- height: 20rem;
- position: relative;
- display: none;
- opacity: 1;
- }
- .show_box .show_item.add_animation_item {
- display: block;
- animation: showItem 0.4s linear forwards, hiddenAvatarItem 0.8s linear 2.7s forwards
- }
- .show_box .show_item .avatar_box {
- width: 20rem;
- height: 20rem;
- border-radius: 15rem;
- overflow: hidden;
- position: absolute;
- top: 0;
- left: 0;
- z-index: 2;
- transform: scale(1);
- display: flex;
- align-items: center;
- }
- .show_box .show_item.add_animation_item .avatar_box {
- animation: showAvatarItem 0.3s linear 2.4s forwards;
- }
- .show_box .show_item .avatar_box .avatar {
- width: 20rem;
- height: 20rem;
- object-fit: cover;
- }
- .show_box .show_item .info_box {
- position: absolute;
- top: -15rem;
- left: -15rem;
- z-index: 1;
- background: rgba(255, 255, 255, 0.7);
- border-radius: 15rem;
- border: 1rem solid #FFFFFF;
- width: 240rem;
- padding: 15rem;
- box-sizing: border-box;
- }
- .show_box .show_item.add_animation_item .info_box {
- animation: hiddenItem 0.3s linear 2.4s forwards;
- }
- .show_box .show_item.show_img_item .info_box {
- top: -175rem;
- left: -15rem;
- }
- .show_box .show_item.show_img_item.add_animation_item .info_box {
- animation: hiddenImgItem 0.3s linear 2.4s forwards;
- }
- @keyframes showItem {
- 0% {
- opacity: 0;
- }
- 100% {
- opacity: 1;
- }
- }
- @keyframes showAvatarItem {
- 0% {
- transform: scale(1);
- }
- 100% {
- transform: scale(2);
- }
- }
- @keyframes hiddenAvatarItem {
- 0% {
- transform: scale(2);
- opacity: 1;
- }
- 100% {
- transform: scale(1);
- opacity: 0;
- top: 135rem;
- left: 172rem;
- }
- }
- @keyframes hiddenItem {
- 0% {
- transform: scale(1);
- top: -15rem;
- left: -15rem;
- }
- 100% {
- transform: scale(0);
- left: -110rem;
- top: -30rem;
- }
- }
- @keyframes hiddenImgItem {
- 0% {
- transform: scale(1);
- top: -175rem;
- left: -15rem;
- }
- 100% {
- transform: scale(0);
- left: -110rem;
- top: -115rem;
- }
- }
- .show_box .show_item .info_box .img_box {
- width: 210rem;
- height: 150rem;
- border-radius: 15rem;
- overflow: hidden;
- margin-bottom: 10rem;
- display: none;
- }
- .show_box .show_item.show_img_item .info_box .img_box {
- display: block;
- }
- .show_box .show_item .info_box .img_box .info_img {
- width: 210rem;
- height: 150rem;
- object-fit: cover;
- }
- .show_box .show_item .info_box .info_text .info_name {
- font-weight: 500;
- font-size: 14rem;
- color: #222222;
- line-height: 20rem;
- padding-left: 25rem;
- margin-bottom: 5rem;
- height: 20rem;
- }
- .show_box .show_item .info_box .info_text .info_dsc {
- font-weight: 400;
- font-size: 12rem;
- color: #222222;
- line-height: 17rem;
- word-break: break-all;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 5;
- overflow: hidden;
- }
- .show_box .show_item.show_img_item .info_box .info_text .info_dsc {
- word-break: break-all;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- overflow: hidden;
- }
- .send_btn {
- width: 345rem;
- position: fixed;
- bottom: 50rem;
- left: 50%;
- transform: translateX(-50%);
- }
- .dialog_text {
- position: fixed;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- background-color: rgba(0, 0, 0, 0.5);
- /* 半透明黑色 */
- z-index: 1000;
- /* 确保遮罩层在顶部 */
- transition: opacity 0.5s ease;
- /* 可选:添加透明度过渡效果 */
- display: none;
- }
- .dialog-body {
- width: 100%;
- height: 100vh;
- z-index: 1001;
- /* 确保遮罩层在顶部 */
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- }
- .text_bg {
- background: url('./img/dialog-text.png');
- background-size: cover;
- width: 100vw;
- height: 368rem;
- }
- .close-text {
- width: 24rem;
- height: 24rem;
- float: right;
- margin-right: 25rem;
- margin-top: 25rem;
- }
- .textarea_style {
- background-color: rgba(255, 255, 255, 0);
- border: unset;
- height: 180rem;
- padding: 0 35rem;
- width: 100%;
- margin: 0;
- font-size: 14rem;
- }
- .textarea_placeHolder {
- color: #999999;
- font-size: 14rem;
- padding: 0 35rem;
- position: absolute;
- top: 0;
- }
- .photo-btn {
- width: 80rem;
- height: 80rem;
- margin-top: 18rem;
- margin-right: 35rem;
- }
- .send_text {
- width: 225rem;
- height: 52rem;
- background: linear-gradient(48deg, #92E4FC 0%, #D0E7F5 100%);
- border-radius: 30rem;
- border: 2rem solid #FFFFFF;
- font-weight: 800;
- font-size: 16px;
- color: #222222;
- margin-top: 15rem;
- }
- .img_list {
- width: 100%;
- overflow-x: auto;
- padding: 0 35rem;
- }
- .imageGallery {
- display: flex;
- overflow-x: auto;
- }
- .imageGallery img {
- width: 80rem;
- height: 80rem;
- margin-top: 18rem;
- margin-right: 35rem;
- }
- .upload-class {
- min-width: 80rem;
- height: 80rem;
- line-height: 80rem;
- font-size: 14px;
- border: 1px solid #c1bfa9;
- border-radius: 10rem;
- text-align: center;
- margin-top: 18rem;
- margin-right: 35rem;
- color: #999;
- }
- input {
- font-size: 14rem;
- }
- .qrcode {
- padding: 20rem;
- }
- .qrcode-img {
- width: 100%;
- height: 100%;
- object-fit: cover;
- margin-bottom: 20rem;
- }
- .qrcode-msg {
- text-align: center;
- font-size: 18rem;
- }
- </style>
- <body>
- <div id="collectPage">
- <div class="bg_content">
- <div class="show_box">
- <div id="showItem" class="show_item">
- <div class="avatar_box">
- <img id="avatar" class="avatar" src="./img/prize-bg.png" />
- </div>
- <div class="info_box">
- <div class="img_box">
- <img id="infoImg" class="info_img" src="./img/lottery-bg.png" />
- </div>
- <div class="info_text">
- <div id="infoName" class="info_name"></div>
- <div id="infoDsc" class="info_dsc"></div>
- </div>
- </div>
- </div>
- </div>
- <img class="send_btn" id="sendBtn" src="./img/send-btn.png" mode="widthFix" />
- </div>
- <div id="dialogText" class="dialog_text">
- <div class="dialog-body">
- <div class="text_bg">
- <img class="close-text" id="closeText" src="./img/close-text.png" mode="widthFix" />
- <div style="position: relative;margin-top: 42rem;">
- <textarea class="textarea_style" id="textarea"></textarea>
- <div class="textarea_placeHolder" id="textareaPlaceHolder">说出您和宝骏汽车的故事,为宝骏云海新车上市送上祝福</div>
- </div>
- <div class="img_list">
- <div id="imageGallery" class="imageGallery">
- <img class="photo-btn" id="photoBtn" src="./img/photo-btn.png" mode="widthFix"
- onclick="uploadImage()" />
- <input type="file" id="uploadfile" style="display: none;" multiple accept='image/*'>
- </div>
- </div>
- </div>
- <button class="send_text" onclick="handleSendText()">发送</button>
- </div>
- </div>
- </div>
- <!-- 二维码 -->
- <div id="qrcode" class="qrcode">
- <img id="qrcode-img" class="qrcode-img" src="" />
- <div id="qrcode-msg" class="qrcode-msg"></div>
- </div>
- <script>
- let httpUrl = true // 初始化时请求地址为真则是正式环境,否则是测试环境
- let h5Type = null
- let credentials = {
- bucket: '',
- Authorization: '',
- secretId: '',
- serverDomain: ''
- }
- let imgList = []
- var itemList = []
- var itemIndex = 0
- var itemTimer = null
- var shareTitle = null
- var shareDes = null
- var shareCover = null
- function uploadImage () {
- let uploaInput = document.getElementById('uploadfile');
- document.getElementById('uploadfile').click();
- // 当用户上传时触发事件
- uploaInput.onchange = function() {
- readFile(this);
- }
- //处理图片并添加都dom中的函数
- let readFile = function(obj) {
- // 获取input里面的文件组
- let fileList = obj.files;
- //对文件组进行遍历,可以到控制台打印出fileList去看看
- for (let i = 0; i < fileList.length; i++) {
- var formData = new FormData();
- formData.append('path', fileList[i].name)
- formData.append('file', fileList[i])
- // 显示上传中状态
- const gallery = document.getElementById('imageGallery');
- const photoBtn = document.getElementById('photoBtn');
- const upload = document.createElement('div');
- upload.className = 'upload-class';
- upload.innerHTML = '上传中...'
- gallery.insertBefore(upload, photoBtn);
- let url = credentials.serverDomain + '/open/v1/file/upload'
- mui.ajax(url, {
- data: formData,
- processData: false,
- contentType: false,
- type: 'post',
- headers: {
- 'bucket': credentials.bucket,
- 'Authorization': credentials.authorization,
- 'secretId': credentials.secretId,
- },
- success: function(res) {
- imgList.push(res.data.url)
- const img = document.createElement('img');
- img.className = 'upload-img';
- img.src = res.data.url;
- gallery.insertBefore(img, photoBtn);
- gallery.removeChild(upload);
- },
- error: function(error) {
- //异常处理;
- console.log(error);
- }
- });
- }
- }
- }
- window.onload = function() {
- if (httpUrl) {
- httpUrl = 'https://wlapi.wefanbot.com'
- } else {
- httpUrl = 'http://test.wefanbot.com:18993'
- }
- if (localStorage.getItem('openId') || getQueryParam('openId')) {
- if (!getQueryParam('externalUserid')) {
- let bId = getQueryParam('bId')
- gerQwAuth(bId);
- } else {
- if (isUnknownType(getQueryParam('externalUserid'))) {
- let bId = getQueryParam('bId')
- gerQwCode(bId);
- } else {
- h5Type = getQueryParam('h5Type')
- if (h5Type == 20) {
- findCollectList()
- document.getElementById('collectPage').style.display = "block"
- }
- getQyWxSign()
- }
- }
- } else {
- // 走授权操作
- getAuth();
- }
- };
- // 内容类型的分享页,获取企业微信的签名
- function getQyWxSign () {
- let shareUrl = `${window.location.origin}?bId=${getQueryParam('bId')}&h5Type=${getQueryParam('h5Type')}`
- mui.ajax(httpUrl + '/scrm/v1/ct-share/p/getSignature', {
- data: {
- url: window.location.href
- },
- dataType: 'json',//服务器返回json格式数据
- type: 'get',//HTTP请求类型
- success: function(res) {
- if (res.code === 1) {
- wx.config({
- debug: false,
- appId: res.data.appId, // 必填,企业号的唯一标识,此处填写企业号corpid
- timestamp: res.data.timestamp, // 必填,生成签名的时间戳
- nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
- signature: res.data.signature, // 必填,签名,见附录1
- jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData'] // 必填,需要使用的JS接口列表
- })
- // 分享接口仅激活的成员数超过200人且已经认证的企业才可在微信上调用。
- wx.ready(() => {
- let shareData = {
- link: shareUrl,
- title: getQueryParam('h5Type') == 19 ? shareTitle : '寻找可靠的伙伴——宝骏14周年车主故事征集', // 分享标题
- desc: getQueryParam('h5Type') == 19 ? shareDes : '暨宝骏云海新车上市500万车主送祝福有奖活动,说出你和宝骏的故事', // 分享描述
- imgUrl: getQueryParam('h5Type') == 19 ? shareCover : 'http://wfg-1631.oss.wefanbot.com/imgUrl.jpg',
- }
- // 分享到朋友圈
- wx.updateAppMessageShareData(shareData)
- // 分享给朋友
- wx.updateTimelineShareData(shareData);
- // 配置失败的回调函数
- wx.error(function(res) {
- // 配置失败
- console.log('配置失败', res);
- })
- })
- }
- },
- error: function(error) {
- //异常处理;
- console.log(error);
- }
- })
- }
- // 公众号授权,获取code
- function getAuth () {
- // 获取url上的code
- let code = getQueryParam('code')
- if (code) {
- let bId = getQueryParam('bId')
- mui.ajax(httpUrl + '/scrm/v1/mp-client/p/getInfoByh5Code', {
- data: {
- code: code,
- bId: bId,
- },
- dataType: 'json',//服务器返回json格式数据
- type: 'get',//HTTP请求类型
- success: function(res) {
- h5Type = res.data.h5Type
- localStorage.setItem('openId', res.data.openId)
- if (h5Type == 20) {
- document.getElementById('collectPage').style.display = "block"
- document.getElementById('lotteryPage').style.display = "none"
- // if (!res.data.externalUserid) {
- // 进行下一步企微授权
- gerQwAuth(bId);
- // }
- }
- },
- error: function(error) {
- //异常处理;
- console.log(error);
- }
- });
- } else {
- let redirect_uri = window.location.href
- // code 不存在,走微信网页授权逻辑
- let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appId=wx99ec0d0828a4d2d3&redirect_uri=${redirect_uri}&scope=snsapi_userinfo&state=STATE#wechat_redirect`
- window.location.replace(url)
- }
- };
- // 企微授权
- function gerQwAuth (bId) {
- let link = window.location.href
- mui.ajax(httpUrl + '/p/insuite/p/getOAUrl', {
- data: {
- bId: bId,
- openId: localStorage.getItem('openId') || getQueryParam('openId'),
- },
- dataType: 'json',//服务器返回json格式数据
- type: 'get',//HTTP请求类型
- success: function(res) {
- if (res.data) {
- window.location.replace(res.data)
- } else {
- mui.toast(res.msg);
- }
- },
- error: function(error) {
- //异常处理;
- console.log(error);
- }
- });
- };
- // 获取二维码
- function gerQwCode (bId) {
- mui.ajax(httpUrl + '/scrm/v1/wxcp-raffle/p/getUnknown', {
- data: {
- bId: bId,
- externalUserId: getQueryParam('externalUserid'),
- },
- dataType: 'json',//服务器返回json格式数据
- type: 'get',//HTTP请求类型
- success: function(res) {
- if (res.data) {
- document.getElementById('qrcode').style.display = "block"
- document.getElementById("qrcode-img").src = res.data.qrCode
- document.getElementById("qrcode-msg").innerHTML = res.data.msg
- } else {
- mui.toast(res.msg);
- }
- },
- error: function(error) {
- //异常处理;
- console.log(error);
- }
- });
- }
- function getCosObj () {
- mui.ajax('https://saasapi.wefango.com/scrm/v1/oss/p/getAuthorization', {
- data: {
- },
- dataType: 'json',//服务器返回json格式数据
- type: 'post',//HTTP请求类型
- headers: { 'Content-Type': 'application/json' },
- success: function(res) {
- credentials = res.data.info
- // 用正则将this.credentials.serverDomain链接中的协议与当前域名的协议保持一致
- credentials.serverDomain = credentials.serverDomain.replace(/https:|http:/g, document.location.protocol)
- console.log('credentials2', credentials);
- },
- error: function(error) {
- //异常处理;
- console.log(error);
- }
- });
- };
- // 发送祝福
- function handleSendText () {
- let bId = getQueryParam('bId')
- let textareaResult = document.getElementById("textarea").value;
- mui.ajax(httpUrl + '/scrm/v1/mp-collect/p/add', {
- data: {
- bId: bId,
- openId: localStorage.getItem('openId') || getQueryParam('openId'),
- content: textareaResult,
- imgList: imgList,
- },
- dataType: 'json',//服务器返回json格式数据
- type: 'post',//HTTP请求类型
- headers: { 'Content-Type': 'application/json' },
- success: function(res) {
- if (res.code == 1) {
- mui.toast('发送成功');
- document.getElementById('dialogText').style.display = 'none';
- imgList = []
- document.getElementById("textarea").value = "";
- document.getElementById('textareaPlaceHolder').innerHTML = '说出您和宝骏汽车的故事,为宝骏云海新车上市送上祝福';
- findCollectList()
- const gallery = document.getElementById('imageGallery');
- // 遍历gallery的所有子元素
- var imgsToRemove = gallery.querySelectorAll('img.upload-img');
- // 遍历找到的元素并移除它们
- imgsToRemove.forEach(function(img) {
- gallery.removeChild(img);
- });
- } else {
- mui.toast(res.msg);
- }
- },
- error: function(error) {
- //异常处理;
- console.log(error);
- }
- });
- };
- // 获取用户故事收集列表
- function findCollectList () {
- mui.ajax(httpUrl + '/scrm/v1/mp-collect/p/findCollectList', {
- data: {
- },
- dataType: 'json',//服务器返回json格式数据
- type: 'get',//HTTP请求类型
- success: function(res) {
- if (res.code == 1) {
- itemList = res.data || []
- itemIndex = 0
- onShowItem()
- } else {
- mui.toast(res.msg);
- }
- },
- error: function(error) {
- //异常处理;
- console.log(error);
- }
- });
- };
- function getRandomArbitrary (min, max) {
- return Math.floor(Math.random() * (max - min) + min);
- }
- function showItem (data) {
- var showItem = document.getElementById('showItem')
- var infoName = document.getElementById('infoName')
- var infoDsc = document.getElementById('infoDsc')
- var avatar = document.getElementById('avatar')
- avatar.src = data.avatar
- infoName.innerText = data.clientName
- infoDsc.innerText = data.content
- var X = getRandomArbitrary(15, 125)
- if (data.imgList && data.imgList.length) {//有图片
- showItem.classList.add("show_img_item")
- var infoImg = document.getElementById('infoImg')
- infoImg.src = data.imgList[0]
- var Y = getRandomArbitrary(175, 208)
- } else {//无图片
- showItem.classList.remove("show_img_item")
- var Y = getRandomArbitrary(15, 157)
- }
- showItem.style.cssText = `top: ${Y}rem; left: ${X}rem;`
- showItem.classList.add("add_animation_item")
- setTimeout(() => {
- showItem.classList.remove("add_animation_item")
- }, 3500)
- }
- function onShowItem () {
- if (itemTimer) {
- clearTimeout(itemTimer)
- itemTimer = null
- }
- if (itemList.length) {
- var data = itemList[itemIndex]
- showItem(data)
- if (itemIndex < itemList.length - 1) {
- itemIndex++
- } else {
- itemIndex = 0
- }
- itemTimer = setTimeout(() => {
- onShowItem()
- }, 4000)
- }
- }
- document.getElementById('sendBtn').addEventListener('click', function() {
- document.getElementById('dialogText').style.display = 'block';
- if (itemTimer) {
- clearTimeout(itemTimer)
- itemTimer = null
- }
- // 获取腾讯COS对象存储的实例对象
- getCosObj();
- });
- document.getElementById('closeText').addEventListener('click', function() {
- document.getElementById('dialogText').style.display = 'none';
- imgList = []
- const gallery = document.getElementById('imageGallery');
- // 遍历gallery的所有子元素
- var imgsToRemove = gallery.querySelectorAll('img.upload-img');
- // 遍历找到的元素并移除它们
- imgsToRemove.forEach(function(img) {
- gallery.removeChild(img);
- });
- document.getElementById("textarea").value = "";
- document.getElementById('textareaPlaceHolder').innerHTML = '说出您和宝骏汽车的故事,为宝骏云海新车上市送上祝福';
- onShowItem()
- });
- document.getElementById('textarea').addEventListener('focus', function() {
- document.getElementById('textareaPlaceHolder').innerHTML = '';
- });
- document.getElementById('textarea').addEventListener('blur', function() {
- if (document.getElementById('textarea').value == '') {
- document.getElementById('textareaPlaceHolder').innerHTML = '说出您和宝骏汽车的故事,为宝骏云海新车上市送上祝福';
- }
- });
- document.getElementById('textareaPlaceHolder').addEventListener('click', function() {
- document.getElementById('textarea').focus();
- })
- // 截取url中的数据
- function getQueryParam (paramName) {
- // 获取当前URL的查询字符串部分
- const queryString = window.location.search;
- // 创建一个URLSearchParams对象
- const urlParams = new URLSearchParams(queryString);
- // 返回指定参数的值,如果不存在则返回null
- return urlParams.get(paramName);
- };
- function isUnknownType(value) {
- // 1. 先检查是否为字符串类型
- // 2. 再检查是否以"unknown"开头(区分大小写)
- return typeof value === 'string' && value.startsWith('unknown');
- };
- </script>
- </body>
- </html>
|