Commit 52685249 by yixinjj

新增文件上传

1 parent a39a640f
<!-- <!--
* @Author: 前端 qianduan01@didihu.com.cn * @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-04-07 17:09:53 * @Date: 2024-04-07 17:09:53
* @LastEditors: 前端 qianduan01@didihu.com.cn * @LastEditors: limin
* @LastEditTime: 2024-04-18 17:59:32 * @LastEditTime: 2024-09-19 11:46:49
* @FilePath: \gl_tape\App.vue * @FilePath: \gl_tape\App.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
--> -->
...@@ -51,7 +51,11 @@ export default { ...@@ -51,7 +51,11 @@ export default {
}, },
onHide: function () {}, onHide: function () {},
onError: function (e) { onError: function (e) {
this.$sendSentry(e) try {
uni.$logger?.error({ msg: e.message || '捕获全局异常', extra: { error: typeof e == 'string' ? e : JSON.stringify(e) } })
} catch (error) {
console.log(error);
}
} }
} }
</script> </script>
......
adb connect 127.0.0.1:16384
\ No newline at end of file \ No newline at end of file
<template> <template>
<view <view class="container" @click="handleTouchStart">
class="container"
@click="handleTouchStart"
>
<view :class="['home', { show: !id }]"> <view :class="['home', { show: !id }]">
<home-animation></home-animation> <home-animation></home-animation>
<left-side :userInfo="userInfo" :tabIndex.sync="tabIndex" @changeTab="$emit('changeTab', $event)" @stopAudio="stopAudio" /> <left-side :userInfo="userInfo" :tabIndex.sync="tabIndex" @changeTab="$emit('changeTab', $event)" @stopAudio="stopAudio" />
<view class="right-side"> <view class="right-side">
<template v-if="tabIndex == 0"> <template v-if="tabIndex == 0">
<view class="right-content"> <view class="right-content">
<view <view class="start" @click="$emit('start')">
class="start" <image class="start-btn" src="../../assets/images/home/start.gif" alt="开始接待" />
@click="$emit('start')" <image class="start-border" src="../../assets/images/home/start-border.png" />
>
<image
class="start-btn"
src="../../assets/images/home/start.gif"
alt="开始接待"
/>
<image
class="start-border"
src="../../assets/images/home/start-border.png"
/>
</view> </view>
<view class="module-list"> <view class="module-list">
<slot name="module" /> <slot name="module" />
...@@ -29,10 +16,7 @@ ...@@ -29,10 +16,7 @@
</view> </view>
</template> </template>
<template v-else> <template v-else>
<component <component :is="componentName" :userInfo="userInfo" />
:is="componentName"
:userInfo="userInfo"
/>
</template> </template>
<view class="store-addr"> <view class="store-addr">
<view class="icon-addr sprite-icon icon-addr"></view> <view class="icon-addr sprite-icon icon-addr"></view>
...@@ -44,102 +28,84 @@ ...@@ -44,102 +28,84 @@
<slot name="detail" /> <slot name="detail" />
</view> </view>
<!-- 未点击开始接待,弹窗 --> <!-- 未点击开始接待,弹窗 -->
<MessageBox <MessageBox ref="previewRef" @confirm="$emit('preview')" :popupW="704" content="直接点击素材可进行预览,若面向车主展示,请点击「开始接待」" confirmBtnText="预览素材"></MessageBox>
ref="previewRef"
@confirm="$emit('preview')"
:popupW="704"
content="直接点击素材可进行预览,若面向车主展示,请点击「开始接待」"
confirmBtnText="预览素材"
></MessageBox>
<!-- 停留弹框 --> <!-- 停留弹框 -->
<MessageBox <MessageBox ref="tipBox" @cancel="tipCancel" @confirm="tipConfirm" content="系统检测到您在当前页面停留较久,是否仍在客户接待中?" cancelBtnText="否" confirmBtnText="是"></MessageBox>
ref="tipBox"
@cancel="tipCancel"
@confirm="tipConfirm"
content="系统检测到您在当前页面停留较久,是否仍在客户接待中?"
cancelBtnText="否"
confirmBtnText="是"
></MessageBox>
<!-- 退出弹框 --> <!-- 退出弹框 -->
<MessageBox <MessageBox :popupW="704" ref="finish" :content="finishContene" :isFooter="false">
:popupW="704"
ref="finish"
:content="finishContene"
:isFooter="false"
>
<view class="footer"> <view class="footer">
<view <view class="footer-btn confirm flex" @click="$emit('openStep')">
class="footer-btn confirm flex"
@click="$emit('openStep')"
>
<template v-if="finishDoneText"> <template v-if="finishDoneText">
{{ finishDoneText }} {{ finishDoneText }}
</template> </template>
<template v-else> 完成接待<text>(推荐)</text> </template> <template v-else>
完成接待
<text>(推荐)</text>
</template>
</view> </view>
<view <view class="footer-btn cancel flex" @click="$emit('backHome')">
class="footer-btn cancel flex" 仍要退出
@click="$emit('backHome')" <text>(不推荐)</text>
>
仍要退出<text>(不推荐)</text>
</view> </view>
</view> </view>
</MessageBox> </MessageBox>
<!-- 升级弹框 --> <!-- 升级弹框 -->
<update-box /> <update-box />
<slot name="content" /> <slot name="content" />
<web-view <web-view @message="handlerMessage" ref="webview" src="/hybrid/html/index.html"></web-view>
@message="handlerMessage"
ref="webview"
src="/hybrid/html/index.html"
></web-view>
</view> </view>
</template> </template>
<script> <script>
import RecordList from './components/RecordList.vue'
import RecordList from "./components/RecordList.vue"; import myClick from '@/mixin/click'
import myClick from "@/mixin/click"; import uploader from '@/mixin/uploader.js'
import uploader from "@/mixin/uploader.js"; import HomeAnimation from './components/HomeAnimation.vue'
import HomeAnimation from './components/HomeAnimation.vue'; import CustomerFile from './components/CustomerFile.vue'
import CustomerFile from './components/CustomerFile.vue'; import LeftSide from './components/LeftSide.vue'
import LeftSide from './components/LeftSide.vue'; import { Ws } from '@/ws/Ws.js'
import config from '@/config.js'
export default { export default {
mixins: [myClick, uploader], mixins: [myClick, uploader],
components: { RecordList, HomeAnimation, CustomerFile, LeftSide }, components: { RecordList, HomeAnimation, CustomerFile, LeftSide },
props: { props: {
id: [String, Number], id: [String, Number],
finishDoneText: String, finishDoneText: String,
finishContene: { finishContene: {
type: String, type: String,
default: "当前操作视为强制退出接待,若需正常流程完成接待请点击“完成接待”", default: '当前操作视为强制退出接待,若需正常流程完成接待请点击“完成接待”'
}, }
}, },
data () { data() {
return { return {
userInfo: {}, userInfo: {},
tabIndex: 0 tabIndex: 0
}; }
}, },
mounted () { mounted() {
const userInfo = uni.$storage.get("userInfo") || {}; const userInfo = uni.$storage.get('userInfo') || {}
this.userInfo = userInfo; this.userInfo = userInfo
this.wsConnet()
}, },
computed: { computed: {
previewRef () { previewRef() {
return this.$refs.previewRef; return this.$refs.previewRef
}, },
finishRef () { finishRef() {
return this.$refs.finish; return this.$refs.finish
}, },
componentName () { componentName() {
if (this.tabIndex == 0) return 'HomeSlot' if (this.tabIndex == 0) return 'HomeSlot'
else if (this.tabIndex == 1) return 'RecordList' else if (this.tabIndex == 1) return 'RecordList'
else return 'CustomerFile' else return 'CustomerFile'
}, }
}, },
methods: { methods: {
}, wsConnet() {
}; const ws = new Ws({ url: config.SOCKET_ADDRESS, token: 123456, deviceId: 12, onMessage: () => {} })
}
}
}
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.container { .container {
......
module.exports = { module.exports = {
// 请求域名 格式:https://xxx.xxx.com // 请求域名 格式:https://xxx.xxx.com
HTTP_REQUEST_URL: "http://127.0.0.1:8000/api", HTTP_REQUEST_URL: 'http://127.0.0.1:8000/api',
// 阿里云oss域名 格式:https://xxx.oss-cn-xxx.aliyuncs.com // 阿里云oss域名 格式:https://xxx.oss-cn-xxx.aliyuncs.com
OSS_DOMAIN: "https://glsk-oss.oss-cn-shenzhen.aliyuncs.com", OSS_DOMAIN: 'https://glsk-oss.oss-cn-shenzhen.aliyuncs.com',
// 文件直传到阿里云oss时需用到 // 文件直传到阿里云oss时需用到
ACCESSKEYID: "LTAI5tCRcCUgd7bt1J7JY596", ACCESSKEYID: 'LTAI5tCRcCUgd7bt1J7JY596',
ACCESSKEYSECRET: "kJos9mgylkR5ztosnDt8Asrc3ulgqy", ACCESSKEYSECRET: 'kJos9mgylkR5ztosnDt8Asrc3ulgqy',
BUKET_NAME: "glsk-oss", BUKET_NAME: 'glsk-oss',
FOLDER: "quality/", FOLDER: 'quality/',
// 与后端约定的token字段名 // 与后端约定的token字段名
TOKEN_NAME: "glsk-oss", TOKEN_NAME: 'glsk-oss',
}; SOCKET_ADDRESS: 'http://192.168.1.129:8080'
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: 前端 qianduan01@didihu.com.cn * @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-04-07 17:09:53 * @Date: 2024-04-07 17:09:53
* @LastEditors: limin * @LastEditors: limin
* @LastEditTime: 2024-09-03 19:12:36 * @LastEditTime: 2024-09-19 11:45:26
* @FilePath: \gl_tape\main.js * @FilePath: \gl_tape\main.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
......
{
"id": "hyoga-uni-socket_io",
"name": "socket.io ui-app版",
"displayName": "socket.io ui-app版",
"version": "3.0.4",
"description": "适用于uni-app的socket.io封装,可用于uni-app、微信小程序",
"keywords": [
"socket.io",
"微信小程序"
],
"dcloudext": {
"category": [
"JS SDK",
"通用 SDK"
]
}
}
\ No newline at end of file \ No newline at end of file
const WsTyps = {
MessageTypes: {
Private: 'private',
System: 'system'
},
Connected:'connect',
Eroor:'error',
Disconnected:'disconnect'
}
export {
WsTyps
}
export * from './constants'
...@@ -9,6 +9,7 @@ class LogCat { ...@@ -9,6 +9,7 @@ class LogCat {
// BufferedReader = plus.android.importClass('java.io.BufferedReader') // BufferedReader = plus.android.importClass('java.io.BufferedReader')
// FileInputStream = plus.android.importClass('java.io.FileInputStream') // FileInputStream = plus.android.importClass('java.io.FileInputStream')
// InputStreamReader = plus.android.importClass('java.io.InputStreamReader') // InputStreamReader = plus.android.importClass('java.io.InputStreamReader')
LogPath = '' LogPath = ''
constructor(folderName = '_zyzs_log') { constructor(folderName = '_zyzs_log') {
if (this.Environment.MEDIA_MOUNTED || !this.Environment.isExternalStorageRemovable()) { if (this.Environment.MEDIA_MOUNTED || !this.Environment.isExternalStorageRemovable()) {
......
...@@ -12,8 +12,8 @@ class Logger { ...@@ -12,8 +12,8 @@ class Logger {
this.fields = fields this.fields = fields
this.init() this.init()
} }
async init() { init() {
const user = await this.getUserInfo() const user = this.getUserInfo()
this.remote = new RemoteLog(user) this.remote = new RemoteLog(user)
this.local = new LocalLog() this.local = new LocalLog()
} }
...@@ -33,18 +33,16 @@ class Logger { ...@@ -33,18 +33,16 @@ class Logger {
this.remote[level](info) this.remote[level](info)
this.local[level](JSON.stringify(info)) this.local[level](JSON.stringify(info))
} }
async getUserInfo() { getUserInfo() {
const userInfo = storageApi.getUserInfo() const userInfo = storageApi.getUserInfo()
console.log('userInfo', userInfo); // const ip = await getIp()
const ip = await getIp()
const user = this.fields.reduce((pre, cur) => { const user = this.fields.reduce((pre, cur) => {
pre[cur] = userInfo[cur] pre[cur] = userInfo[cur]
return pre return pre
}, {}) }, {})
user.name = userInfo.name user.name = userInfo.name
user.merchantName = userInfo.merchantName user.merchantName = userInfo.merchantName
user.ip = ip // user.ip = ip
return user return user
} }
} }
......
import LogsHandler from './/handlers/LogsHandler'
import { Orders } from './constants'
export const Mapper = {
get: order => Map[order]
}
const Map = {
[Orders.Logs]: LogsHandler
}
import io from '@/uni_modules/hyoga-uni-socket_io/uni-socket.io.js'
import { WsTyps } from '../utils/common'
import WsHandlerFactory from './factory'
// const WsTyps = common.constants.WsTyps
export class Ws {
url
token
deviceId
onMessage
ws
constructor({ url, token, deviceId, onMessage }) {
this.url = url
this.token = token
this.deviceId = deviceId
this.onMessage = onMessage
this.connect()
}
connect() {
const { token, deviceId, url } = this
this.ws = io(url, {
auth: { token, deviceId },
transports: ['websocket'],
timeout: 5000
})
this.subscribe()
}
subscribe() {
this.ws.on(WsTyps.Connected, () => {
console.log('ws 已连接')
})
this.ws.on(WsTyps.MessageTypes.Private, function (data) {
const handler = WsHandlerFactory.getInstance().create(data.order)
handler.work(this.deviceId,data.payload)
}.bind(this))
this.ws.on(WsTyps.MessageTypes.System, function (data) {
console.log('消息', data)
})
this.ws.on(WsTyps.Disconnected, function () {
console.log('Disconnected')
})
this.ws.on(WsTyps.Eroor, msg => {
console.log('ws error', msg)
})
}
send(type = WsTyps.MessageTypes.Private, data) {
this.ws.emit(type, data)
}
}
const Orders = {
Logs: 'logs',
}
export { Orders }
import { Mapper } from './Mapper'
export default class WsHandlerFactory {
store = new Map()
static instance = null
constructor() {
if (this.instance) {
return this.instance
}
this.instance = this
}
static getInstance() {
if (!WsHandlerFactory.instance) {
WsHandlerFactory.instance = new WsHandlerFactory()
}
return WsHandlerFactory.instance
}
create(order) {
const Handler = Mapper.get(order)
if (!Handler) {
throw new Error('未找到对应的Handler')
}
if (!this.store.has(Handler.name)) {
this.store.set(Handler.name, new Handler())
}
return this.store.get(Handler.name)
}
}
export default class LogsHandler {
logFile = null
constructor() {
this.logFile = uni.$logger.local.logger
}
getLogFileList() {
return this.logFile.getLogFileList()
}
upload(deviceId, data) {
const files = this.getLogFileList()
this.process(files, deviceId)
}
process(files, deviceId) {
files.forEach(file => this.post(file, deviceId))
}
post({ name, path }, deviceId) {
uni.uploadFile({
url: 'http://192.168.1.129:3000/file/upload',
filePath: path,
name: 'file',
header: {
'Content-Type': 'multipart/form-data'
},
formData: {
deviceId
},
success: res => {
console.log(res)
},
fail: res => {
console.log(res)
},
complete: res => {
// console.log(res)
}
})
}
work(deviceId, data) {
this.upload(deviceId, data)
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!