123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584 |
- //reconnect-websocket
- ;(function (global, factory) {
- if (typeof define === 'function' && define.amd) {
- define([], factory)
- } else if (typeof module !== 'undefined' && module.exports) {
- module.exports = factory()
- } else {
- global.ReconnectingWebSocket = factory()
- }
- })(this || window, function () {
- if (!('WebSocket' in window)) {
- console.warn('此浏览器不支持WebSocket')
- return
- }
- if ('ReconnectingWebSocket' in window) {
- return
- }
- function ReconnectingWebSocket(url, protocols, options) {
- // Default settings
- var settings = {
- /** Whether this instance should log debug messages. */
- debug: false,
- /** Whether or not the websocket should attempt to connect immediately upon instantiation. */
- automaticOpen: true,
- /** The number of milliseconds to delay before attempting to reconnect. */
- reconnectInterval: 1000,
- /** The maximum number of milliseconds to delay a reconnection attempt. */
- maxReconnectInterval: 30000,
- /** The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. */
- reconnectDecay: 1.5,
- /** The maximum time in milliseconds to wait for a connection to succeed before closing and retrying. */
- timeoutInterval: 2000,
- /** The maximum number of reconnection attempts to make. Unlimited if null. */
- maxReconnectAttempts: null,
- /** The binary type, possible values 'blob' or 'arraybuffer', default 'blob'. */
- binaryType: 'blob',
- }
- if (!options) {
- options = {}
- }
- // Overwrite and define settings with options if they exist.
- for (var key in settings) {
- if (typeof options[key] !== 'undefined') {
- this[key] = options[key]
- } else {
- this[key] = settings[key]
- }
- }
- // These should be treated as read-only properties
- /** The URL as resolved by the constructor. This is always an absolute URL. Read only. */
- this.url = url
- /** The number of attempted reconnects since starting, or the last successful connection. Read only. */
- this.reconnectAttempts = 0
- /**
- * The current state of the connection.
- * Can be one of: WebSocket.CONNECTING, WebSocket.OPEN, WebSocket.CLOSING, WebSocket.CLOSED
- * Read only.
- */
- this.readyState = WebSocket.CONNECTING
- /**
- * A string indicating the name of the sub-protocol the server selected; this will be one of
- * the strings specified in the protocols parameter when creating the WebSocket object.
- * Read only.
- */
- this.protocol = null
- // Private state variables
- var self = this
- var ws
- var forcedClose = false
- var timedOut = false
- var eventTarget = document.createElement('div')
- // Wire up "on*" properties as event handlers
- eventTarget.addEventListener('open', function (event) {
- self.onopen(event)
- })
- eventTarget.addEventListener('close', function (event) {
- self.onclose(event)
- })
- eventTarget.addEventListener('connecting', function (event) {
- self.onconnecting(event)
- })
- eventTarget.addEventListener('message', function (event) {
- self.onmessage(event)
- })
- eventTarget.addEventListener('error', function (event) {
- self.onerror(event)
- })
- // Expose the API required by EventTarget
- this.addEventListener = eventTarget.addEventListener.bind(eventTarget)
- this.removeEventListener = eventTarget.removeEventListener.bind(eventTarget)
- this.dispatchEvent = eventTarget.dispatchEvent.bind(eventTarget)
- /**
- * This function generates an event that is compatible with standard
- * compliant browsers and IE9 - IE11
- *
- * This will prevent the error:
- * Object doesn't support this action
- *
- * http://stackoverflow.com/questions/19345392/why-arent-my-parameters-getting-passed-through-to-a-dispatched-event/19345563#19345563
- * @param s String The name that the event should use
- * @param args Object an optional object that the event will use
- */
- function generateEvent(s, args) {
- var evt = document.createEvent('CustomEvent')
- evt.initCustomEvent(s, false, false, args)
- return evt
- }
- this.open = function (reconnectAttempt) {
- ws = new WebSocket(self.url, protocols || [])
- ws.binaryType = this.binaryType
- if (reconnectAttempt) {
- if (this.maxReconnectAttempts && this.reconnectAttempts > this.maxReconnectAttempts) {
- return
- }
- } else {
- eventTarget.dispatchEvent(generateEvent('connecting'))
- this.reconnectAttempts = 0
- }
- if (self.debug || ReconnectingWebSocket.debugAll) {
- console.debug('ReconnectingWebSocket', 'attempt-connect', self.url)
- }
- var localWs = ws
- var timeout = setTimeout(function () {
- if (self.debug || ReconnectingWebSocket.debugAll) {
- console.debug('ReconnectingWebSocket', 'connection-timeout', self.url)
- }
- timedOut = true
- localWs.close()
- timedOut = false
- }, self.timeoutInterval)
- ws.onopen = function (event) {
- clearTimeout(timeout)
- if (self.debug || ReconnectingWebSocket.debugAll) {
- console.debug('ReconnectingWebSocket', 'onopen', self.url)
- }
- self.protocol = ws.protocol
- self.readyState = WebSocket.OPEN
- self.reconnectAttempts = 0
- var e = generateEvent('open')
- e.isReconnect = reconnectAttempt
- reconnectAttempt = false
- eventTarget.dispatchEvent(e)
- }
- ws.onclose = function (event) {
- clearTimeout(timeout)
- ws = null
- if (forcedClose) {
- self.readyState = WebSocket.CLOSED
- eventTarget.dispatchEvent(generateEvent('close'))
- } else {
- self.readyState = WebSocket.CONNECTING
- var e = generateEvent('connecting')
- e.code = event.code
- e.reason = event.reason
- e.wasClean = event.wasClean
- eventTarget.dispatchEvent(e)
- if (!reconnectAttempt && !timedOut) {
- if (self.debug || ReconnectingWebSocket.debugAll) {
- console.debug('ReconnectingWebSocket', 'onclose', self.url)
- }
- eventTarget.dispatchEvent(generateEvent('close'))
- }
- var timeout =
- self.reconnectInterval * Math.pow(self.reconnectDecay, self.reconnectAttempts)
- setTimeout(
- function () {
- self.reconnectAttempts++
- self.open(true)
- },
- timeout > self.maxReconnectInterval ? self.maxReconnectInterval : timeout
- )
- }
- }
- ws.onmessage = function (event) {
- if (self.debug || ReconnectingWebSocket.debugAll) {
- console.debug('ReconnectingWebSocket', 'onmessage', self.url, event.data)
- }
- var e = generateEvent('message')
- e.data = event.data
- eventTarget.dispatchEvent(e)
- }
- ws.onerror = function (event) {
- if (self.debug || ReconnectingWebSocket.debugAll) {
- console.debug('ReconnectingWebSocket', 'onerror', self.url, event)
- }
- eventTarget.dispatchEvent(generateEvent('error'))
- }
- }
- // Whether or not to create a websocket upon instantiation
- if (this.automaticOpen == true) {
- this.open(false)
- }
- /**
- * Transmits data to the server over the WebSocket connection.
- *
- * @param data a text string, ArrayBuffer or Blob to send to the server.
- */
- this.send = function (data) {
- if (ws) {
- if (self.debug || ReconnectingWebSocket.debugAll) {
- console.debug('ReconnectingWebSocket', 'send', self.url, data)
- }
- return ws.send(data)
- } else {
- throw 'INVALID_STATE_ERR : Pausing to reconnect websocket'
- }
- }
- /**
- * Closes the WebSocket connection or connection attempt, if any.
- * If the connection is already CLOSED, this method does nothing.
- */
- this.close = function (code, reason) {
- // Default CLOSE_NORMAL code
- if (typeof code == 'undefined') {
- code = 1000
- }
- forcedClose = true
- if (ws) {
- ws.close(code, reason)
- }
- }
- /**
- * Additional public API method to refresh the connection if still open (close, re-open).
- * For example, if the app suspects bad data / missed heart beats, it can try to refresh.
- */
- this.refresh = function () {
- if (ws) {
- ws.close()
- }
- }
- }
- /**
- * An event listener to be called when the WebSocket connection's readyState changes to OPEN;
- * this indicates that the connection is ready to send and receive data.
- */
- ReconnectingWebSocket.prototype.onopen = function (event) {}
- /** An event listener to be called when the WebSocket connection's readyState changes to CLOSED. */
- ReconnectingWebSocket.prototype.onclose = function (event) {}
- /** An event listener to be called when a connection begins being attempted. */
- ReconnectingWebSocket.prototype.onconnecting = function (event) {}
- /** An event listener to be called when a message is received from the server. */
- ReconnectingWebSocket.prototype.onmessage = function (event) {}
- /** An event listener to be called when an error occurs. */
- ReconnectingWebSocket.prototype.onerror = function (event) {}
- /**
- * Whether all instances of ReconnectingWebSocket should log debug messages.
- * Setting this to true is the equivalent of setting all instances of ReconnectingWebSocket.debug to true.
- */
- ReconnectingWebSocket.debugAll = false
- ReconnectingWebSocket.CONNECTING = WebSocket.CONNECTING
- ReconnectingWebSocket.OPEN = WebSocket.OPEN
- ReconnectingWebSocket.CLOSING = WebSocket.CLOSING
- ReconnectingWebSocket.CLOSED = WebSocket.CLOSED
- return ReconnectingWebSocket
- })
- let indidocxModule = {
- version: '2023.0412.01',
- createInstance(options) {
- let indidocxobj = {
- //对象属性
- slCtl: {
- id: 0, //slctl的唯一id
- forWindowID: CreateRandomId(),
- $$idx: {},
- Activation: '',
- initPortID: 0,
- domain: '127.0.0.1',
- curFileType: 'default',
- strNeedSaveMark: 'false',
- strPageNumUrl: '',
- strPageNum: '',
- strWaterMarkUrl: '',
- strWaterMark: '',
- strWaterMarkParam: '',
- strPageHeader: '',
- strPageHeaderUrl: '',
- strSpace: '',
- uploadCompentInfoUrl: 'api/framework/v1/indidocx/saveIndidocxMessage',
- doTime: new Date(),
- isV6PluginInstall: false,
- isFileOpen: false,
- curPromise: {},
- checkInstall: function (argsobj, froceUpdate = false) {
- indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
- if (window.idxProcessCheck && !froceUpdate) {
- return window.idxProcessCheck
- }
- if (window.sessionStorage && sessionStorage.getItem('isV6PluginInstall') !== null) {
- indidocxobj.slCtl.isV6PluginInstall = JSON.parse(sessionStorage.getItem('isV6PluginInstall'))
- return Promise.resolve(indidocxobj.slCtl.isV6PluginInstall)
- }
- window.idxProcessCheck = indidocxobj.slCtl.Content.Control._initHttpServer(6000)
- return window.idxProcessCheck
- },
- getRef: function (str, start, substr, seperator) {
- var pos
- var endpos
- pos = str.indexOf(substr, start)
- if (pos == -1) return ''
- endpos = str.indexOf(seperator, pos + 1)
- if (endpos == -1) return str.substring(pos + substr.length, str.length)
- else return str.substring(pos + substr.length, endpos)
- },
- getFileType: function (strFileName) {
- var arrtmp = strFileName.split('.')
- return '.' + arrtmp.pop().toLowerCase()
- },
- htmldecode: function (s) {
- return s
- // var div = document.createElement('div')
- // div.innerHTML = s
- // return div.textContent
- },
- setFileList: function (data) {
- var strlist = new Array()
- for (var i = 0; i < data.length; i++) {
- strlist.push(
- data[i].properties +
- '<FileServerUrl>' +
- fnGetFileLink(data[i].code) +
- '</FileServerUrl>'
- )
- }
- if (strlist != null && strlist != undefined) {
- indidocxobj.slCtl.Content.Files._FileInfoString = strlist
- indidocxobj.slCtl.Content.Files.FileList = indidocxobj.slCtl.analyzeFileList() //解析filelist
- }
- },
- analyzeFileList: function () {
- var arrFileMap = indidocxobj.slCtl.Content.Files._FileInfoString.map(function (
- onefile,
- index
- ) {
- var filelink = ''
- if (typeof fnGetFileLink === 'function') {
- filelink = fnGetFileLink(
- indidocxobj.slCtl.getRef(onefile, 0, '<file_unid>', '</file_unid>')
- )
- }
- return {
- FileName: indidocxobj.slCtl.htmldecode(
- indidocxobj.slCtl.getRef(onefile, 0, '<file_name>', '</file_name>')
- ),
- Unid: indidocxobj.slCtl.getRef(onefile, 0, '<file_unid>', '</file_unid>'),
- CatNum: indidocxobj.slCtl.getRef(onefile, 0, '<CatNum>', '</CatNum>'),
- Size: indidocxobj.slCtl.getRef(onefile, 0, '<file_size>', '</file_size>'),
- FileType: indidocxobj.slCtl.getRef(onefile, 0, '<filetype>', '</filetype>'),
- Completed: parseInt(
- indidocxobj.slCtl.getRef(onefile, 0, '<completed>', '</completed>')
- ),
- doAdd:
- indidocxobj.slCtl.getRef(onefile, 0, '<doAdd>', '</doAdd>') == 'True'
- ? true
- : false,
- Type: indidocxobj.slCtl.getFileType(
- indidocxobj.slCtl.getRef(onefile, 0, '<file_name>', '</file_name>')
- ),
- CreateInfo: indidocxobj.slCtl.getRef(onefile, 0, '<CreateInfo>', '</CreateInfo>'),
- UpdateInfo: indidocxobj.slCtl.getRef(onefile, 0, '<UpdateInfo>', '</UpdateInfo>'),
- TaodaInfo: indidocxobj.slCtl.getRef(onefile, 0, '<TaodaInfo>', '</TaodaInfo>'),
- NeedUpdate: indidocxobj.slCtl.getRef(onefile, 0, '<NeedUpdate>', '</NeedUpdate>'),
- AllowPrint: false,
- DocUnid: indidocxobj.slCtl.getRef(onefile, 0, '<doc_unid>', '</doc_unid>'),
- Uploading:
- parseInt(indidocxobj.slCtl.getRef(onefile, 0, '<completed>', '</completed>')) ==
- 0 && indidocxobj.slCtl.getRef(onefile, 0, '<doAdd>', '</doAdd>') == 'False'
- ? true
- : false,
- Link: filelink,
- }
- })
- return arrFileMap
- },
- socketSend: function (url, opts) {
- if ('function' == typeof opts) {
- fn = opts
- opts = {}
- }
- if (!opts) opts = {}
- var prefix = opts.prefix || '__jp'
- // use the callback name that was passed if one was provided.
- // otherwise generate a unique name by incrementing our counter.
- var id = opts.name || prefix + this.count++
- var param = opts.param || 'callback'
- // add qs component
- var action = url.substr(url.lastIndexOf('/') + 1)
- action += (~action.indexOf('?') ? '&' : '?') + param + '=' + encodeURIComponent(id)
- action = action.replace('?&', '?')
- this.socketSendSafe(action, 5)
- },
- socketSendSafe(msg, times = 5) {
- if (times <= 0) {
- console.warn('通信中断')
- var start = msg.indexOf('callback') + 16
- var callback = msg.substr(start, msg.indexOf('&', start) - start)
- window[callback] && window[callback]({ Update: false })
- return
- }
- var curconn = window.IndidocxShareSocket || indidocxobj.slCtl.socket
- if (curconn.readyState == WebSocket.CONNECTING) {
- console.log('连接中')
- setTimeout(function () {
- indidocxobj.slCtl.socketSendSafe(msg, times - 1)
- }, 500)
- } else if (
- curconn.readyState == WebSocket.CLOSED ||
- curconn.readyState == WebSocket.CLOSING
- ) {
- curconn.open()
- console.log('重新启动socket')
- setTimeout(function () {
- indidocxobj.slCtl.socketSendSafe(msg, times - 1)
- }, 500)
- } else {
- //OPEN
- curconn.send(msg)
- }
- },
- receiveMsg: function (msg) {
- // console.log('get message ' + msg.data)
- eval(msg.data)
- },
- //控件传输层 V6控件发送请求 以后控件更换逻辑只需修改此函数即可
- sendRequest: function (action, contentJson, timeout, method) {
- contentJson.sid = indidocxobj.slCtl.id
- contentJson.Activation = indidocxobj.slCtl.Activation
- contentJson.base_host = location.origin
- contentJson.cookie = indidocxobj.slCtl.$$idx.httpserver.cookie
- contentJson.refresh_token = indidocxobj.slCtl.$$idx.httpserver.refresh_token
- contentJson.getActivationUrl = indidocxobj.slCtl.$$idx.httpserver.getActivationUrl
- contentJson.action = action
- contentJson.doTime = Date.now()
- var queryString = ''
- for (var key in contentJson) {
- queryString += key + '=' + encodeURIComponent(contentJson[key]) + '&'
- }
- indidocxobj.slCtl.socketSend(action, { param: queryString, timeout })
- },
- formatParams: function (argsobj) {
- var $$idxtemp = {}
- $$idxtemp.httpserver = {}
- $$idxtemp.httpserver.sid = argsobj.sid == undefined ? 'testuser' : argsobj.sid
- $$idxtemp.httpserver.Activation =
- argsobj.Activation == undefined ? '' : argsobj.Activation
- $$idxtemp.httpserver.UserName = argsobj.UserName == undefined ? 'admin' : argsobj.UserName
- $$idxtemp.httpserver.MaxFileSize =
- argsobj.MaxFileSize == undefined ? '20' : argsobj.MaxFileSize
- $$idxtemp.httpserver.SetTakeLogConfig =
- argsobj.SetTakeLogConfig == undefined ? 'true' : argsobj.SetTakeLogConfig
- $$idxtemp.httpserver.RefuseFileType =
- argsobj.RefuseFileType == undefined ? '' : argsobj.RefuseFileType
- $$idxtemp.httpserver.AcceptFileType =
- argsobj.AcceptFileType == undefined ? '' : argsobj.AcceptFileType
- $$idxtemp.httpserver.UseMark = argsobj.UseMark == undefined ? 'true' : argsobj.UseMark
- $$idxtemp.httpserver.ContentNeedFormate =
- argsobj.ContentNeedFormate == undefined ? '' : argsobj.ContentNeedFormate
- $$idxtemp.httpserver.TaoDaType = argsobj.TaoDaType == undefined ? '' : argsobj.TaoDaType
- $$idxtemp.httpserver.DirDeleteTime =
- argsobj.DirDeleteTime == undefined ? '' : argsobj.DirDeleteTime
- $$idxtemp.httpserver.FileFilter =
- argsobj.FileFilter == undefined ? '' : argsobj.FileFilter
- $$idxtemp.httpserver.MultiText = argsobj.MultiText == undefined ? '' : argsobj.MultiText
- $$idxtemp.httpserver.MaxAttachCount =
- argsobj.MaxAttachCount == undefined ? '' : argsobj.MaxAttachCount
- $$idxtemp.httpserver.UseRevise = argsobj.UseRevise == undefined ? '' : argsobj.UseRevise
- $$idxtemp.httpserver.UploadParam =
- argsobj.UploadParam == undefined ? '' : argsobj.UploadParam
- $$idxtemp.httpserver.UploadUrl = argsobj.UploadUrl == undefined ? '' : argsobj.UploadUrl
- $$idxtemp.httpserver.ServerUpdateUrl =
- argsobj.ServerUpdateUrl == undefined ? '' : argsobj.ServerUpdateUrl
- $$idxtemp.httpserver.cookie =
- argsobj.cookie == undefined ? '' : this.Base64.encode(argsobj.cookie)
- $$idxtemp.httpserver.refresh_token =
- argsobj.refresh_token == undefined ? '' : this.Base64.encode(argsobj.refresh_token)
- $$idxtemp.httpserver.getActivationUrl =
- argsobj.getActivationUrl == undefined ? '' : argsobj.getActivationUrl
- $$idxtemp.idxV6version = argsobj.idxV6version == undefined ? '' : argsobj.idxV6version
- indidocxobj.slCtl.id = $$idxtemp.httpserver.sid
- indidocxobj.slCtl.Activation = $$idxtemp.httpserver.Activation
- return $$idxtemp
- },
- // V6控件打开附件
- fnV6OpenFile: function (fname, fileparam) {
- indidocxobj.slCtl.isFileOpen = true
- var promise = new Promise((resolve, reject) => {
- let eventName = indidocxobj.slCtl.registerEvent('_OpenFileCompleted_', resolve, false)
- var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
- var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
- if (userfile == null) {
- userfile = {}
- ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
- }
- var action = '/openfile'
- if (fileparam.NeedUpdate === undefined)
- fileparam.NeedUpdate = [1, 3, 2].indexOf(Number(fileparam.Status)) == -1
- var contentJson = {
- fileunid: userfile.Unid,
- fileinfo: usefileinfostring,
- fileparam: JSON.stringify(fileparam),
- UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
- UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
- UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
- callback: 'window.' + eventName,
- }
- var timeout = 0 // 60 * 5000
- indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
- }).catch(function (reason) {
- indidocxobj.slCtl.isFileOpen = false
- return Promise.reject(reason)
- })
- return promise
- },
- CreateTrackFileName: function (sourcename) {
- var count = 1
- var tmp = null
- var files = indidocxobj.slCtl.Content.Files
- for (var i = 0; i < files.FileList.length; i++) {
- var userFile = files.FileList[i]
- var filename = userFile.FileName
- if (filename.indexOf('痕迹稿') != -1 && filename.indexOf('_' + sourcename) != -1) {
- count++
- }
- }
- tmp = '痕迹稿' + count + '_' + sourcename //痕迹1_正文.doc
- return tmp
- },
- getV8IDXAddress: function () {
- if (window.location.protocol == 'http:') {
- return 'ws://' + indidocxobj.slCtl.domain + ':15880/indidocx'
- } else {
- return 'wss://' + indidocxobj.slCtl.domain + ':15881/indidocx'
- }
- },
- /**
- * 注册回调事件
- * @param {string} eventType 事件类型
- * @param {function} resolve
- * @param {boolean} isfileopen 标识打开文件
- * @returns {string} 事件名称
- */
- registerEvent(eventType, resolve, isfileopen) {
- let eventName = eventType + CreateRandomId() + '_' + indidocxobj.slCtl.forWindowID
- indidocxobj.slCtl.curPromise[eventName] = resolve
- window[eventName] = function (o) {
- if (isfileopen !== undefined) indidocxobj.slCtl.isFileOpen = isfileopen
- if (typeof fnRefreshFileList === 'function') {
- fnRefreshFileList()
- }
- if (o == undefined) {
- indidocxobj.slCtl.curPromise[eventName](false)
- return
- }
- //此处需要返回操作回调的参数
- indidocxobj.slCtl.curPromise[eventName](o)
- }
- return eventName
- },
- launchBrowser: function (url, type) {
- var action = '/launchie'
- var contentJson = {
- starturl: url,
- browser: type,
- }
- this.sendRequest(action, contentJson)
- },
- Content: {
- Files: {
- FileList: [],
- _FileInfoString: [],
- FileUploadDoing: function () {},
- AllFilePost: function () {},
- ErrorOccurred: function () {},
- SingleFileUploadFinished: function () {},
- FileDeleted: function () {},
- DupNameFile: function () {},
- _anylaze: function () {},
- _syncFileInfo: function () {},
- },
- Control: {
- ReadHTML: function () {},
- getHTMLed: function () {},
- getLablesed: function () {},
- FileConvertPDFed: function () {},
- FileAdded: function () {},
- ActionEnd: function () {},
- EventRegioned: function () {},
- SingleFileDownloaded: function () {},
- SilentDownloaded: function () {},
- ErrorMessage: function () {},
- OnFileSelected: function () {},
- getPrintListed: function () {},
- SaveFileCompleted: function () {},
- _getversionCompleted: function (o) {
- console.log(o.message)
- },
- _getFileStatued: function () {},
- _inithttpCompleted: function () {},
- _initHttpServer: function (timeout, tresolve, treject) {
- var promise = new Promise((resolve, reject) => {
- let eventName = '_inithttpCompleted_' + indidocxobj.slCtl.forWindowID
- window[eventName] = function (o) {
- var returnValue = false
- if (indidocxobj.slCtl.isV6PluginInstall != false) {
- //已经初始化成功
- returnValue = indidocxobj.slCtl.isV6PluginInstall
- resolve(returnValue)
- tresolve && tresolve(returnValue)
- return
- }
- if (o == undefined) {
- //伪成功事件
- indidocxobj.slCtl.isV6PluginInstall = false
- returnValue = indidocxobj.slCtl.isV6PluginInstall
- return
- }
- if (o.Update != '' && o.querystring != undefined) {
- indidocxobj.slCtl.isV6PluginInstall = o
- //this.Content.Control._synMessage();
- returnValue = o
- if (window.sessionStorage) {
- sessionStorage.setItem('isV6PluginInstall', JSON.stringify(o))
- }
- if (o.querystring.indexOf('授权') > -1) {
- returnValue = o.querystring
- }
- if (!!indidocxobj.slCtl.uploadCompentInfoUrl)
- indidocxobj.slCtl.Content.Control._uploadCompentInfo(o)
- }
- resolve(returnValue) //是否安装控件
- tresolve && tresolve(returnValue)
- }
- var baseUrl = '/inithttpserver'
- var contentJson = {
- idxversion: indidocxobj.slCtl.$$idx.idxV6version,
- ServerUpdateUrl: indidocxobj.slCtl.$$idx.httpserver.ServerUpdateUrl,
- UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
- UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
- UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
- callback: 'window.' + eventName,
- }
- indidocxobj.slCtl.sendRequest(baseUrl, contentJson, 30000, 'get')
- if (timeout == undefined) {
- timeout = 8000
- }
- setTimeout(window[eventName], timeout)
- }).catch(function (reason) {
- return Promise.reject(reason)
- })
- return promise
- },
- _uploadCompentInfo: function (serverinfo) {
- var state = JSON.parse(sessionStorage.getItem('vuex'))
- var userinfo = state?.sd?.common?.userInfo?.default || {}
- var data = {
- userId: userinfo.id,
- userAccount: userinfo.account,
- userName: userinfo.name,
- updateDate: Date.now(), //当前日期的毫秒值
- controlType: 'IndidocX',
- // browsername: navigator.userAgent,
- equipmentName: serverinfo.HostName,
- indidocxVersion: serverinfo.Update, //inididoc版本
- }
- var ajax = indidocxobj.slCtl.createXHR()
- ajax.open('POST', indidocxobj.slCtl.uploadCompentInfoUrl)
- ajax.onreadystatechange = function () {
- if (ajax.readyState == 4 && ajax.status == 200) {
- console.log('上传组件信息成功')
- }
- }
- ajax.setRequestHeader('Cache-Control', 'no-cache')
- ajax.setRequestHeader('Content-type', 'application/json;charset=utf-8')
- ajax.setRequestHeader('Authorization', state?.sd?.login?.tokens?.access_token)
- ajax.send(JSON.stringify(data))
- },
- _getServerMessage: function (o) {
- if (typeof handleIdxMessage === 'function') {
- handleIdxMessage(o)
- }
- indidocxobj.slCtl.Content.Control._synMessage()
- },
- _synMessage: function () {
- let eventName = '_getServerMessage_' + indidocxobj.slCtl.forWindowID
- var baseUrl = '/synmessage'
- var contentJson = {
- sid: indidocxobj.slCtl.id,
- callback: 'window.' + eventName,
- }
- indidocxobj.slCtl.sendRequest(baseUrl, contentJson, 3000000, 'get')
- },
- _getVersion: function () {
- let eventName = '_getversionCompleted_' + indidocxobj.slCtl.forWindowID
- var baseUrl = '/getversion'
- var contentJson = {
- sid: indidocxobj.slCtl.id,
- callback: 'window.' + eventName,
- }
- indidocxobj.slCtl.sendRequest(baseUrl, contentJson, 30000, 'get')
- },
- _getTerminalInfo: function () {
- let eventName = '_geTerminalInfoCompleted_' + indidocxobj.slCtl.forWindowID
- var baseUrl = '/getterminalinfo'
- var contentJson = {
- sid: indidocxobj.slCtl.id,
- callback: 'window.' + eventName,
- }
- indidocxobj.slCtl.sendRequest(baseUrl, contentJson, 30000, 'get')
- },
- getFileByName: function (fname) {
- var userfile = null
- indidocxobj.slCtl.Content.Files.FileList.map(function (onefile, index) {
- if (onefile.Unid == fname || onefile.FileName == fname) {
- userfile = onefile
- }
- })
- return userfile
- },
- _getFileInfoByName: function (fname) {
- var usefileinfostring = null
- indidocxobj.slCtl.Content.Files._FileInfoString.map(function (onefile, index) {
- if (
- indidocxobj.slCtl.getRef(onefile, 0, '<file_unid>', '</file_unid>') == fname ||
- indidocxobj.slCtl.htmldecode(
- indidocxobj.slCtl.getRef(onefile, 0, '<file_name>', '</file_name>')
- ) == fname
- ) {
- usefileinfostring = onefile
- }
- })
- return usefileinfostring
- },
- //编辑
- EditFile: function (fname, fileparam, argsobj) {
- indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
- return indidocxobj.slCtl.fnV6OpenFile(fname, fileparam)
- },
- //打开本地文件夹
- OpenLoaclDir: function (openpath, argsobj) {
- var promise = new Promise((resolve, reject) => {
- let eventName = indidocxobj.slCtl.registerEvent('_OpenLoaclDirCompleted_', resolve)
- indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
- var action = '/openloacldir'
- var contentJson = {
- openfiledir: openpath,
- callback: 'window.' + eventName,
- }
- var timeout = 60 * 5000
- indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
- }).catch(function (reason) {
- return Promise.reject(reason)
- })
- return promise
- },
- //下载附件
- SaveFileToLocal: function (fname, fileparam, argsobj) {
- var promise = new Promise((resolve, reject) => {
- let eventName = indidocxobj.slCtl.registerEvent('_SaveFileCompleted_', resolve)
- indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
- var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
- var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
- if (userfile == null) {
- userfile = {}
- ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
- }
- var action = '/downloadfile'
- if (fileparam == undefined) fileparam = ''
- var contentJson = {
- fileunid: userfile.Unid,
- fileparam: JSON.stringify(fileparam),
- fileinfo: usefileinfostring,
- callback: 'window.' + eventName,
- }
- var timeout = 60 * 5000
- indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
- }).catch(function (reason) {
- return Promise.reject(reason)
- })
- return promise
- },
- //批量下载
- SaveMultiFiles: function (strFiles, fileparam, argsobj) {
- var promise = new Promise((resolve, reject) => {
- let eventName = indidocxobj.slCtl.registerEvent('_SaveFileCompleted_', resolve)
- indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
- if (fileparam == undefined) fileparam = ''
- var arrFileNames = strFiles.split('|')
- var strFilesInfo = ''
- for (var j = 0, len = arrFileNames.length; j < len; j++) {
- if (arrFileNames[j] != '') {
- for (
- var i = 0, ten = indidocxobj.slCtl.Content.Files.FileList.length;
- i < ten;
- i++
- ) {
- if (arrFileNames[j] == indidocxobj.slCtl.Content.Files.FileList[i].FileName) {
- if (
- indidocxobj.slCtl.Content.Files.FileList[i].Link.indexOf('fileName') > 0
- ) {
- strFilesInfo += '|' + indidocxobj.slCtl.Content.Files.FileList[i].Link
- } else {
- strFilesInfo +=
- '|' +
- indidocxobj.slCtl.Content.Files.FileList[i].Link +
- '?fileName=' +
- arrFileNames[j]
- }
- }
- }
- }
- }
- var action = '/downloadmultifile'
- var contentJson = {
- fileparam: JSON.stringify(fileparam),
- files: strFilesInfo,
- callback: 'window.' + eventName,
- }
- var timeout = 60 * 5000
- indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
- }).catch(function (reason) {
- return Promise.reject(reason)
- })
- return promise
- },
- //清稿
- QingGao: function (fname, fileparam, argsobj) {
- indidocxobj.slCtl.isFileOpen = true
- var promise = new Promise((resolve, reject) => {
- let eventName = indidocxobj.slCtl.registerEvent(
- '_OpenFileCompleted_',
- resolve,
- false
- )
- indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
- var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
- var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
- if (userfile == null) {
- userfile = {}
- ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
- }
- var _files = ''
- for (
- var j = 0, len = indidocxobj.slCtl.Content.Files.FileList.length;
- j < len;
- j++
- ) {
- _files += '|' + indidocxobj.slCtl.Content.Files.FileList[j].FileName
- }
- var action = '/qinggao'
- var contentJson = {
- fileunid: userfile.Unid,
- fileinfo: usefileinfostring,
- fileparam: JSON.stringify(fileparam),
- UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
- UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
- UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
- trackFileName: indidocxobj.slCtl.CreateTrackFileName(fname),
- callback: 'window.' + eventName,
- }
- var timeout = 0 //60 * 2000
- indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
- }).catch(function (reason) {
- indidocxobj.slCtl.isFileOpen = false
- return Promise.reject(reason)
- })
- return promise
- },
- //套打
- TaoDa: function (
- ModelUrl,
- ContentFieldName,
- fname,
- fileparam,
- OldDocName,
- values,
- taodainfo,
- argsobj
- ) {
- var replacename = ''
- if (checkFileExt(ModelUrl, '.docx')) {
- replacename = CreateRandomId() + '.docx'
- } else if (checkFileExt(ModelUrl, '.doc')) {
- replacename = CreateRandomId() + '.doc'
- }
- ModelUrl = changeURLArg(ModelUrl, 'fileName', replacename)
- indidocxobj.slCtl.isFileOpen = true
- var promise = new Promise((resolve, reject) => {
- let eventName = indidocxobj.slCtl.registerEvent(
- '_OpenFileCompleted_',
- resolve,
- false
- )
- indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
- var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
- var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
- if (userfile == null) {
- userfile = {}
- ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
- } else {
- var infoarr = usefileinfostring.split('<TaodaInfo>')
- usefileinfostring =
- infoarr[0] +
- '<TaodaInfo>' +
- taodainfo +
- '</TaodaInfo>' +
- infoarr[1].split('</TaodaInfo>')[1]
- //更新taodainfo
- for (var i = 0; i < indidocxobj.slCtl.Content.Files._FileInfoString.length; i++) {
- if (
- indidocxobj.slCtl.getRef(
- indidocxobj.slCtl.Content.Files._FileInfoString[i],
- 0,
- '<file_unid>',
- '</file_unid>'
- ) == fname ||
- indidocxobj.slCtl.getRef(
- indidocxobj.slCtl.Content.Files._FileInfoString[i],
- 0,
- '<file_name>',
- '</file_name>'
- ) == fname
- ) {
- indidocxobj.slCtl.Content.Files._FileInfoString.splice(
- i,
- 1,
- usefileinfostring
- )
- }
- }
- }
- var _files = ''
- for (
- var j = 0, len = indidocxobj.slCtl.Content.Files.FileList.length;
- j < len;
- j++
- ) {
- _files += '|' + indidocxobj.slCtl.Content.Files.FileList[j].FileName
- }
- var action = '/taoda'
- var contentJson = {
- fileunid: userfile.Unid,
- olddocname: OldDocName,
- model_url: ModelUrl,
- contentfieldname: ContentFieldName,
- fieldvalues: JSON.stringify(values),
- fileparam: JSON.stringify(fileparam),
- fileinfo: usefileinfostring,
- UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
- UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
- UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
- callback: 'window.' + eventName,
- }
- var timeout = 0 // 60 * 2000
- indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
- }).catch(function (reason) {
- indidocxobj.slCtl.isFileOpen = false
- return Promise.reject(reason)
- })
- return promise
- },
- //盖章
- GaiZhang: function (
- ModelUrl,
- ContentFieldName,
- fname,
- fileparam,
- OldDocName,
- values,
- argsobj
- ) {
- var replacename = ''
- if (checkFileExt(ModelUrl, '.docx')) {
- replacename = CreateRandomId() + '.docx'
- } else if (checkFileExt(ModelUrl, '.doc')) {
- replacename = CreateRandomId() + '.doc'
- }
- ModelUrl = changeURLArg(ModelUrl, 'fileName', replacename)
- indidocxobj.slCtl.isFileOpen = true
- var promise = new Promise((resolve, reject) => {
- let eventName = indidocxobj.slCtl.registerEvent(
- '_OpenFileCompleted_',
- resolve,
- false
- )
- indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
- var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
- var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
- if (userfile == null) {
- userfile = {}
- ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
- }
- var action = '/gaizhang'
- var contentJson = {
- fileunid: userfile.Unid,
- model_url: ModelUrl,
- contentfieldname: ContentFieldName,
- fileparam: JSON.stringify(fileparam),
- fieldvalues: JSON.stringify(values),
- fileinfo: usefileinfostring,
- UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
- UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
- UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
- callback: 'window.' + eventName,
- }
- var timeout = 0 // 60 * 2000
- indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
- }).catch(function (reason) {
- indidocxobj.slCtl.isFileOpen = false
- return Promise.reject(reason)
- })
- return promise
- },
- //更新正文
- UpdateRegion: function (fname, values, picvalues, fileparam, argsobj) {
- indidocxobj.slCtl.isFileOpen = true
- var promise = new Promise((resolve, reject) => {
- let eventName = indidocxobj.slCtl.registerEvent(
- '_OpenFileCompleted_',
- resolve,
- false
- )
- indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
- var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
- var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
- if (userfile == null) {
- userfile = {}
- ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
- }
- var action = '/updateregion'
- var contentJson = {
- fieldvalues: JSON.stringify(values),
- picvalues: picvalues,
- fileunid: userfile.Unid,
- fileparam: JSON.stringify(fileparam),
- fileinfo: usefileinfostring,
- UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
- UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
- UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
- callback: 'window.' + eventName,
- }
- var timeout = 0 // 60 * 2000
- indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
- }).catch(function (reason) {
- indidocxobj.slCtl.isFileOpen = false
- return Promise.reject(reason)
- })
- return promise
- },
- //文档打印
- PrintDocument: function (fname, fileparam, values, argsobj) {
- var promise = new Promise((resolve, reject) => {
- let eventName = indidocxobj.slCtl.registerEvent('_OpenFileCompleted_', resolve)
- indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
- var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
- var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
- if (userfile == null) {
- userfile = {}
- ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
- }
- var action = '/printdocument'
- var contentJson = {
- fieldvalues: JSON.stringify(values),
- fileunid: userfile.Unid,
- fileparam: JSON.stringify(fileparam),
- fileinfo: usefileinfostring,
- UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
- UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
- UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
- callback: 'window.' + eventName,
- }
- var timeout = 0 // 60 * 2000
- indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
- }).catch(function (reason) {
- return Promise.reject(reason)
- })
- return promise
- },
- //转换pdf
- DOCConvertToPDF: function (fname, fileparam, argsobj) {
- indidocxobj.slCtl.isFileOpen = true
- var promise = new Promise((resolve, reject) => {
- let eventName = indidocxobj.slCtl.registerEvent('_OpenFileCompleted_', resolve)
- indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
- var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
- var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
- if (userfile == null) {
- userfile = {}
- ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
- }
- var action = '/convertdoctopdf'
- var contentJson = {
- fileunid: userfile.Unid,
- fileinfo: usefileinfostring,
- UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
- UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
- UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
- callback: 'window.' + eventName,
- }
- var timeout = 0 // 60 * 5000
- indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
- }).catch(function (reason) {
- indidocxobj.slCtl.isFileOpen = false
- return Promise.reject(reason)
- })
- return promise
- },
- DOCConvertToOFD: function (fname, fileparam, argsobj) {
- var promise = new Promise((resolve, reject) => {
- let eventName = indidocxobj.slCtl.registerEvent('_OpenFileCompleted_', resolve)
- indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
- var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
- var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
- if (userfile == null) {
- userfile = {}
- ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
- }
- var action = '/convertdoctoofd'
- var contentJson = {
- fileunid: userfile.Unid,
- fileinfo: usefileinfostring,
- UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
- UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
- UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
- callback: 'window.' + eventName,
- }
- var timeout = 0 //60 * 5000
- indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
- }).catch(function (reason) {
- return Promise.reject(reason)
- })
- return promise
- },
- //图片章
- TuPianZhang: function (fname, fileparam, argsobj) {
- var promise = new Promise((resolve, reject) => {
- let eventName = indidocxobj.slCtl.registerEvent('_TuPianZhangCompleted_', resolve, false)
- var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
- var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
- if (userfile == null) {
- userfile = {}
- ; (userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
- }
- var action = '/tupianzhang'
- var contentJson = {
- fileunid: userfile.Unid,
- fileinfo: usefileinfostring,
- fileparam: JSON.stringify(fileparam),
- UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
- UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
- UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
- callback: 'window.' + eventName,
- }
- var timeout = 0 // 60 * 5000
- indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
- }).catch(function (reason) {
- return Promise.reject(reason)
- })
- return promise
- },
- },
- },
- createXHR: function () {
- if (typeof XMLHttpRequest != 'undefined') {
- //兼容高版本浏览器
- return new XMLHttpRequest()
- } else if (typeof ActiveXObject != 'undefined') {
- //IE6 采用 ActiveXObject, 兼容IE6
- var versions = [
- //由于MSXML库有3个版本,因此都要考虑
- 'MSXML2.XMLHttp.6.0',
- 'MSXML2.XMLHttp.3.0',
- 'MSXML2.XMLHttp',
- ]
- for (var i = 0; i < versions.length; i++) {
- try {
- return new ActiveXObject(versions[i])
- } catch (e) {
- //跳过
- }
- }
- } else {
- throw new Error('您的浏览器不支持XHR对象')
- }
- },
- Base64: {
- base64EncodeChars: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
- base64DecodeChars: new Array(
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- 62,
- -1,
- -1,
- -1,
- 63,
- 52,
- 53,
- 54,
- 55,
- 56,
- 57,
- 58,
- 59,
- 60,
- 61,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- 0,
- 1,
- 2,
- 3,
- 4,
- 5,
- 6,
- 7,
- 8,
- 9,
- 10,
- 11,
- 12,
- 13,
- 14,
- 15,
- 16,
- 17,
- 18,
- 19,
- 20,
- 21,
- 22,
- 23,
- 24,
- 25,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- 26,
- 27,
- 28,
- 29,
- 30,
- 31,
- 32,
- 33,
- 34,
- 35,
- 36,
- 37,
- 38,
- 39,
- 40,
- 41,
- 42,
- 43,
- 44,
- 45,
- 46,
- 47,
- 48,
- 49,
- 50,
- 51,
- -1,
- -1,
- -1,
- -1,
- -1
- ),
- base64encode: function (str) {
- var out, i, len
- var c1, c2, c3
- len = str.length
- i = 0
- out = ''
- while (i < len) {
- c1 = str.charCodeAt(i++) & 0xff
- if (i == len) {
- out += this.base64EncodeChars.charAt(c1 >> 2)
- out += this.base64EncodeChars.charAt((c1 & 0x3) << 4)
- out += '=='
- break
- }
- c2 = str.charCodeAt(i++)
- if (i == len) {
- out += this.base64EncodeChars.charAt(c1 >> 2)
- out += this.base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4))
- out += this.base64EncodeChars.charAt((c2 & 0xf) << 2)
- out += '='
- break
- }
- c3 = str.charCodeAt(i++)
- out += this.base64EncodeChars.charAt(c1 >> 2)
- out += this.base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4))
- out += this.base64EncodeChars.charAt(((c2 & 0xf) << 2) | ((c3 & 0xc0) >> 6))
- out += this.base64EncodeChars.charAt(c3 & 0x3f)
- }
- return out
- },
- base64decode: function (str) {
- var c1, c2, c3, c4
- var i, len, out
- len = str.length
- i = 0
- out = ''
- while (i < len) {
- do {
- c1 = this.base64DecodeChars[str.charCodeAt(i++) & 0xff]
- } while (i < len && c1 == -1)
- if (c1 == -1) break
- do {
- c2 = this.base64DecodeChars[str.charCodeAt(i++) & 0xff]
- } while (i < len && c2 == -1)
- if (c2 == -1) break
- out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4))
- do {
- c3 = str.charCodeAt(i++) & 0xff
- if (c3 == 61) return out
- c3 = this.base64DecodeChars[c3]
- } while (i < len && c3 == -1)
- if (c3 == -1) break
- out += String.fromCharCode(((c2 & 0xf) << 4) | ((c3 & 0x3c) >> 2))
- do {
- c4 = str.charCodeAt(i++) & 0xff
- if (c4 == 61) return out
- c4 = this.base64DecodeChars[c4]
- } while (i < len && c4 == -1)
- if (c4 == -1) break
- out += String.fromCharCode(((c3 & 0x03) << 6) | c4)
- }
- return out
- },
- utf16to8: function (str) {
- var out, i, len, c
- out = ''
- len = str.length
- for (i = 0; i < len; i++) {
- c = str.charCodeAt(i)
- if (c >= 0x0001 && c <= 0x007f) {
- out += str.charAt(i)
- } else if (c > 0x07ff) {
- out += String.fromCharCode(0xe0 | ((c >> 12) & 0x0f))
- out += String.fromCharCode(0x80 | ((c >> 6) & 0x3f))
- out += String.fromCharCode(0x80 | ((c >> 0) & 0x3f))
- } else {
- out += String.fromCharCode(0xc0 | ((c >> 6) & 0x1f))
- out += String.fromCharCode(0x80 | ((c >> 0) & 0x3f))
- }
- }
- return out
- },
- utf8to16: function (str) {
- var out, i, len, c
- var char2, char3
- out = ''
- len = str.length
- i = 0
- while (i < len) {
- c = str.charCodeAt(i++)
- switch (c >> 4) {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- // 0xxxxxxx
- out += str.charAt(i - 1)
- break
- case 12:
- case 13:
- // 110x xxxx 10xx xxxx
- char2 = str.charCodeAt(i++)
- out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f))
- break
- case 14:
- // 1110 xxxx 10xx xxxx 10xx xxxx
- char2 = str.charCodeAt(i++)
- char3 = str.charCodeAt(i++)
- out += String.fromCharCode(
- ((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0)
- )
- break
- }
- }
- return out
- }, //end
- encode: function (input) {
- return this.base64encode(this.utf16to8(input))
- },
- decode: function (str) {
- return this.utf8to16(this.base64decode(str))
- },
- },
- },
- }
- /**
- * 获取随机ID
- * @returns string
- */
- function CreateRandomId() {
- return Number(Math.random().toString().substr(3, 3) + Date.now()).toString(36)
- }
- /**
- * 修改url参数
- */
- function changeURLArg(url, arg, arg_val) {
- var pattern = arg + '=([^&]*)'
- var replaceText = arg + '=' + arg_val
- if (url.match(pattern)) {
- var tmp = '/(' + arg + '=)([^&]*)/gi'
- tmp = url.replace(eval(tmp), replaceText)
- return tmp
- } else {
- if (url.match('[?]')) {
- return url + '&' + replaceText
- } else {
- return url + '?' + replaceText
- }
- }
- }
- /**
- * 判断后缀
- */
- function checkFileExt(filename, ext) {
- var index = filename.lastIndexOf('.')
- filename = filename.substring(index)
- if (filename.toLowerCase() == ext) {
- return true
- } else {
- return false
- }
- }
- if (!window.slCtlList) {
- window.slCtlList = []
- }
- window.slCtlList.push(indidocxobj)
- //初始化socket
- var conn = window.IndidocxShareSocket || indidocxobj.slCtl.socket
- if (conn == undefined) {
- conn = new ReconnectingWebSocket(indidocxobj.slCtl.getV8IDXAddress())
- conn.onmessage = indidocxobj.slCtl.receiveMsg
- window.IndidocxShareSocket = conn
- indidocxobj.slCtl.socket = conn
- }
- return indidocxobj
- },
- }
- export default indidocxModule
|