123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- var isProduction = ~location.host.indexOf('schcur.com');
- //判断是新建答题卡,还是根据已经有的试卷信息生成答题卡
- //GetQueryString('new') === 'true';
- var isNewBuild = ~location.href.indexOf('online/third')
- String.prototype.substitute = function(data) {
- if (data && typeof data == 'object') {
- return this.replace(/\{([^{}]+)\}/g, function(match, key) {
- var value = data[key]
- return value !== undefined ? '' + value : ''
- })
- } else {
- return this.toString()
- }
- }
- String.prototype.clearFixible = function(){
- return this.replace(/<div class="flexible_icon"(.*)><i class="resize_nwse"><\/i><\/div>/g,'')
- }
- function GetQueryString(name) {
- var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
- var r = window.location.search.substr(1).match(reg) //search,查询?后面的参数,并匹配正则
- if (r != null) return unescape(r[2])
- return null
- }
- //将base64转换为文件对象
- function dataURLtoFile(dataurl, filename) {
- var arr = dataurl.split(',')
- var mime = arr[0].match(/:(.*?);/)[1]
- var bstr = atob(arr[1])
- var n = bstr.length
- var u8arr = new Uint8Array(n)
- while (n--) {
- u8arr[n] = bstr.charCodeAt(n)
- }
- //转换成file对象
- return new File([u8arr], filename, { type: mime })
- //转换成成blob对象
- //return new Blob([u8arr], { type: mime })
- }
- function UnitConversion() {
- /**
- * 获取DPI
- * @returns {Array}
- */
- this.conversion_getDPI = function() {
- var arrDPI = new Array()
- if (window.screen.deviceXDPI) {
- arrDPI[0] = window.screen.deviceXDPI
- arrDPI[1] = window.screen.deviceYDPI
- } else {
- var tmpNode = document.createElement('DIV')
- tmpNode.style.cssText =
- 'width:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden'
- document.body.appendChild(tmpNode)
- arrDPI[0] = parseInt(tmpNode.offsetWidth)
- arrDPI[1] = parseInt(tmpNode.offsetHeight)
- tmpNode.parentNode.removeChild(tmpNode)
- }
- return arrDPI
- }
- /**
- * px转换为mm
- * @param value
- * @returns {number}
- */
- this.pxConversionMm = function(value) {
- var inch = value / this.conversion_getDPI()[0]
- var c_value = inch * 25.4
- return c_value
- }
- /**
- * mm转换为px
- * @param value
- * @returns {number}
- */
- this.mmConversionPx = function(value) {
- /**
- * in 英尺单位 1in = 25.4 mm
- */
- var inch = value / 25.4
- var c_value = inch * this.conversion_getDPI()[0]
- return c_value
- }
- }
- //复选
- function CheckBoxItem($checkBox, allFn, singleFn) {
- this.allFn = allFn || function() {}
- this.singleFn = singleFn || function() {}
- this.$checBox = $checkBox
- //除了 全选 禁用按钮以外的其他按钮的集合
- this.totalCount = this.$checBox.find(
- '.h_checkItem:not(".checkAll"):not(".disabled")'
- ).length
- this.checkedItemsCount = 0
- this.bindEvent()
- }
- CheckBoxItem.prototype.bindEvent = function() {
- var self = this
- this.$checBox.on('click', '.h_checkItem', function() {
- var isDisabled = $(this).hasClass('disabled')
- var isChecked = $(this).hasClass('checked')
- var isCheckAllEl = $(this).hasClass('checkAll')
- if (isDisabled) return
- $(this)[isChecked ? 'removeClass' : 'addClass']('checked')
- if (isCheckAllEl) {
- var checkItems = $(this).siblings('.h_checkItem')
- checkItems[isChecked ? 'removeClass' : 'addClass']('checked')
- self.checkedItemsCount = isChecked ? 0 : checkItems.length
- self.allFn($(this), !isChecked)
- } else {
- var checkAll = $(this).siblings('.checkAll')
- !isChecked ? self.checkedItemsCount++ : self.checkedItemsCount--
- var isCheckAllStatus = self.checkedItemsCount >= self.totalCount
- checkAll[isCheckAllStatus ? 'addClass' : 'removeClass']('checked')
- self.singleFn($(this), !isChecked)
- }
- })
- }
- // 单选
- function RadioBoxItem($radioBox, fn) {
- this.$radioBox = $radioBox
- this.cb = fn
- this.bindEvent()
- }
- RadioBoxItem.prototype.bindEvent = function() {
- var self = this
- this.$radioBox.on('click', '.h_radioItem', function() {
- var isDisabled = $(this).hasClass('disabled')
- var isChecked = $(this).hasClass('checked')
- if (isDisabled) return
- $(this)
- .addClass('checked')
- .siblings('.h_radioItem')
- .removeClass('checked')
- self.cb && self.cb($(this))
- })
- }
- // 切换
- function Switch($switch, fn, defaultstatus) {
- this.$switch = $switch
- this.status = defaultstatus || false
- this.cb = fn || function() {}
- this.bindEvent()
- }
- Switch.prototype.bindEvent = function() {
- var self = this
- this.$switch.click(function() {
- $(this).toggleClass('open')
- self.status = !self.status
- self.cb && self.cb(self.status)
- })
- }
- //layer使用判断
- window.hgc_layer = layui.layer
- window.logs = isProduction?window.console.log:function(){}
- function simpleCopy(obj) {
- return JSON.parse(JSON.stringify(obj))
- }
- //公共弹框
- var hgc_modal = {
- tpl:
- '<div class="hgc_modalBox">\
- <div class="hgc_modal">\
- <h2><em>{title}</em><i class="close">X</i></h2>\
- <div class="modalContent">{content}</div>\
- <div class="modalBtns">\
- <span class="h_btn sure">{ensureText}</span>\
- <span class="h_btn cancel">{cancelText}</span>\
- </div>\
- </div>\
- </div>',
- init: function(data) {
- this.title = data.title || '消息提示'
- this.conetnt = data.content || '提示消息'
- this.ensureText = data.ensureText || '确定'
- this.cancelText = data.cancelText || '取消'
- this.sureCb = data.sureCb || function() {}
- this.cancelCb = data.cancelCb || function() {}
- this.afterCb = data.afterCb || function() {}
- this.render()
- this.initDom()
- this.bindEvent()
- },
- initDom: function() {
- this.$modalBox = $('.hgc_modalBox')
- },
- render: function(content) {
- var self = this
- $('body').append(
- self.tpl.substitute({
- content: self.conetnt,
- title: self.title ,
- ensureText:self.ensureText,
- cancelText:self.cancelText
- })
- )
- self.afterCb && self.afterCb()
- },
- bindEvent: function() {
- var self = this
- //
- self.$modalBox.find('.modalBtns .sure').click(function() {
- self.sureCb()
- self.$modalBox.remove()
- })
- self.$modalBox.find('.modalBtns .cancel').click(function() {
- self.$modalBox.remove()
- self.cancelCb()
-
- })
- self.$modalBox.find('h2 .close').click(function() {
- self.$modalBox.remove()
- })
- }
- }
- //阿拉伯数字和中文数字转换
- function SectionToChinese(section) {
- var chnNumChar = ['', '一', '二', '三', '四', '五', '六', '七', '八', '九']
- var chnUnitChar = ['', '十', '百', '千']
- var strIns = '',chnStr = ''
- var unitPos = 0
- var zero = true
- while (section > 0) {
- var v = section % 10
- if (v === 0) {
- if (!zero) {
- zero = true
- chnStr = chnNumChar[v] + chnStr
- }
- } else {
- zero = false
- strIns = chnNumChar[v]
- strIns += chnUnitChar[unitPos]
- chnStr = strIns + chnStr
- }
- unitPos++
- section = Math.floor(section / 10)
- }
- return chnStr
- }
- /**
- * log 日志函数
- * 可以配置过滤参数
- */
- window.log = function(obj,filterKey){
- if(Object.prototype.toString.call(obj) === '[object Object]'){
- var filterFn = filterKey?function(key,val){
- if(key === filterKey){
- return null
- }
- return val
- }:null
- console.log(JSON.stringify(obj,filterFn,4))
- }else{
- console.log(obj)
- }
-
- }
- //全局生成唯一key
- var uid = 0;
- function guid() {
- var uidStart = Object.keys(Print.questionMap).length;
- return 'modelId'+ ++uidStart
- };
- function _symbolId() {
- return Math.random().toString(36).substr(3,10);
- };
- //字符串转base64
- function encode(str){
- // 对字符串进行编码
- var encode = encodeURI(str);
- // 对编码的字符串转化base64
- var base64 = btoa(encode);
- return base64;
- };
- // base64转字符串
- function decode(base64){
- // 对base64转编码
- var decode = atob(base64);
- // 编码转字符串
- var str = decodeURI(decode);
- return str;
- }
- ;function isBase64 (str){
- if(!str || !str.trim()) return false;
- try {
- return btoa(atob(str)) == str
- } catch (error) {
- return false
- }
- }
|