app
parent
b248bcf13f
commit
1d273741a7
@ -1,234 +1,235 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="p-bill-index g_w_all g_h_all g_bg_f_5 g_kuaishou">
|
<view class="p-bill-index g_w_all g_h_all g_bg_f_5 g_kuaishou">
|
||||||
<view class="m-search g_flex_row_between flex_center g_bg_f g_pl_10 g_pr_10 g_pb_8 g_pt_6 g_mb_10">
|
<view class="m-search g_flex_row_between flex_center g_bg_f g_pl_10 g_pr_10 g_pb_8 g_pt_6 g_mb_10">
|
||||||
<u-search class="g_flex_1" :focus="true" @btnSearch="getSearch" height="80" v-model="keyword" :placeholder="placeholder" bg-color="#ededed" :show-action="false" @change="getSearch" @clear="getSearch" @custom="getSearch" @search="getSearch" search-icon-color="#999999" :maxlength="20"></u-search>
|
<u-search class="g_flex_1" :focus="true" @btnSearch="getSearch" height="80" v-model="keyword" :placeholder="placeholder" bg-color="#ededed" :show-action="false" @change="getSearch" @clear="getSearch" @custom="getSearch" @search="getSearch" search-icon-color="#999999" :maxlength="20"></u-search>
|
||||||
<view class="g_ml_8 g_fs_16" style="color: #576b95" hover-class="thover" @click="backPrev">取消</view>
|
<view class="g_ml_8 g_fs_16" style="color: #576b95" hover-class="thover" @click="backPrev">取消</view>
|
||||||
</view>
|
</view>
|
||||||
<view v-if="whichPage == 'home' || whichPage == 'record'">
|
<view v-if="whichPage == 'home' || whichPage == 'record'">
|
||||||
<g-list-job @uploadList="getList" :list="jobQuery.list" v-if="keyword || whichPage == 'record'" :from="whichPage" :loading="loading" :speed="speed" :query="jobQuery" emptyText="暂无搜索结果" emptySubText=" " />
|
|
||||||
</view>
|
<g-list-job @uploadList="getList" :list="jobQuery.list" v-if="keyword || whichPage == 'record'" :from="whichPage" :loading="loading" :speed="speed" :query="jobQuery" emptyText="暂无搜索结果" emptySubText=" " />
|
||||||
<view v-if="whichPage == 'bill'">
|
</view>
|
||||||
<g-list-job @uploadList="getList" :list="jobQuery.list" v-if="keyword" :loading="loading" :speed="speed" :query="jobQuery" emptyText="暂无搜索结果" emptySubText=" " />
|
<view v-if="whichPage == 'bill'">
|
||||||
</view>
|
<g-list-job @uploadList="getList" :list="jobQuery.list" v-if="keyword" :loading="loading" :speed="speed" :query="jobQuery" emptyText="暂无搜索结果" emptySubText=" " />
|
||||||
<view v-if="whichPage == 'apply'">
|
</view>
|
||||||
<g-list-apply @uploadList="getApplyList('concat')" :list="jobQuery.list" v-if="keyword" :tabActive="applyType" from="home" bg="" class="g_bg_f" @shareJob="shareJob" :loading="loading" :speed="speed" :isLogin="true" :query.sync="jobQuery" :navInfo="navInfo" />
|
<view v-if="whichPage == 'apply'">
|
||||||
</view>
|
<g-list-apply @uploadList="getApplyList('concat')" :list="jobQuery.list" v-if="keyword" :tabActive="applyType" from="home" bg class="g_bg_f" @shareJob="shareJob" :loading="loading" :speed="speed" :isLogin="true" :query.sync="jobQuery" :navInfo="navInfo" />
|
||||||
</view>
|
</view>
|
||||||
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
onReady() {
|
onReady() {
|
||||||
this.G.setNavStyle();
|
this.G.setNavStyle()
|
||||||
},
|
},
|
||||||
onShareAppMessage() {
|
onShareAppMessage() {
|
||||||
return this.G.shareFun();
|
return this.G.shareFun()
|
||||||
},
|
},
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
console.log(options);
|
console.log(options)
|
||||||
this.whichPage = options.from;
|
this.whichPage = options.from
|
||||||
if (this.whichPage == "record" || this.whichPage == "home") {
|
if (this.whichPage == 'record' || this.whichPage == 'home') {
|
||||||
this.placeholder = "搜索职位名称";
|
this.placeholder = '搜索职位名称'
|
||||||
uni.setNavigationBarTitle({
|
uni.setNavigationBarTitle({
|
||||||
title: "搜索职位",
|
title: '搜索职位',
|
||||||
});
|
})
|
||||||
this.getList();
|
this.getList()
|
||||||
} else if (this.whichPage == "apply") {
|
} else if (this.whichPage == 'apply') {
|
||||||
// 工单的类型 0 我报的 1 报给我的
|
// 工单的类型 0 我报的 1 报给我的
|
||||||
this.applyType = options.active;
|
this.applyType = options.active
|
||||||
this.placeholder = "搜索姓名/职位/手机号";
|
this.placeholder = '搜索姓名/职位/手机号'
|
||||||
uni.setNavigationBarTitle({
|
uni.setNavigationBarTitle({
|
||||||
title: "搜索工单",
|
title: '搜索工单',
|
||||||
});
|
})
|
||||||
this.getApplyList();
|
this.getApplyList()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 组件名称
|
// 组件名称
|
||||||
name: "",
|
name: '',
|
||||||
// 局部注册的组件
|
// 局部注册的组件
|
||||||
components: {},
|
components: {},
|
||||||
// 组件参数 接收来自父组件的数据
|
// 组件参数 接收来自父组件的数据
|
||||||
props: {},
|
props: {},
|
||||||
// 组件状态值
|
// 组件状态值
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
whichPage: "",
|
whichPage: '',
|
||||||
keyword: "",
|
keyword: '',
|
||||||
loading: true,
|
loading: true,
|
||||||
speed: -1,
|
speed: -1,
|
||||||
applyType: 0,
|
applyType: 0,
|
||||||
jobQuery: {
|
jobQuery: {
|
||||||
page: 1,
|
page: 1,
|
||||||
size: 50,
|
size: 50,
|
||||||
list: [],
|
list: [],
|
||||||
isFinish: -1,
|
isFinish: -1,
|
||||||
},
|
},
|
||||||
placeholder: "搜索职位名称",
|
placeholder: '搜索职位名称',
|
||||||
navInfo: {},
|
navInfo: {},
|
||||||
};
|
}
|
||||||
},
|
},
|
||||||
// 计算属性
|
// 计算属性
|
||||||
computed: {},
|
computed: {},
|
||||||
// 侦听器
|
// 侦听器
|
||||||
watch: {},
|
watch: {},
|
||||||
created() {},
|
created() {},
|
||||||
mounted() {},
|
mounted() {},
|
||||||
onShow() {
|
onShow() {
|
||||||
let that = this;
|
let that = this
|
||||||
that.navInfo = that.G.getNavInfo();
|
|
||||||
},
|
that.navInfo = that.G.getNavInfo()
|
||||||
// 组件方法
|
},
|
||||||
methods: {
|
// 组件方法
|
||||||
getSearch(e) {
|
methods: {
|
||||||
console.log(e);
|
getSearch(e) {
|
||||||
this.speed = -1;
|
console.log(e)
|
||||||
this.keyword = e;
|
this.speed = -1
|
||||||
this.jobQuery.page = 1;
|
this.keyword = e
|
||||||
console.log(this.whichPage);
|
this.jobQuery.page = 1
|
||||||
if (this.whichPage == "home" || this.whichPage == "record") {
|
console.log(this.whichPage)
|
||||||
this.getList();
|
if (this.whichPage == 'home' || this.whichPage == 'record') {
|
||||||
} else if (this.whichPage == "apply") {
|
this.getList()
|
||||||
this.getApplyList();
|
} else if (this.whichPage == 'apply') {
|
||||||
}
|
this.getApplyList()
|
||||||
},
|
}
|
||||||
backPrev() {
|
},
|
||||||
console.log("backPrev");
|
backPrev() {
|
||||||
uni.navigateBack({
|
console.log('backPrev')
|
||||||
delta: 1,
|
uni.navigateBack({
|
||||||
});
|
delta: 1,
|
||||||
},
|
})
|
||||||
getList($type = "init") {
|
},
|
||||||
let that = this;
|
getList($type = 'init') {
|
||||||
that.G.Post(
|
let that = this
|
||||||
that.api.job_list,
|
let jobConfig = {
|
||||||
{
|
pageNum: that.jobQuery.page,
|
||||||
pageNum: that.jobQuery.page,
|
pageSize: that.jobQuery.size,
|
||||||
pageSize: that.jobQuery.size,
|
agencyId: that.whichPage == 'home' || that.whichPage == 'record' ? '' : uni.getStorageSync('apply-agencyId'),
|
||||||
agencyId: that.whichPage == "home" || that.whichPage == "record" ? "" : uni.getStorageSync("apply-agencyId"),
|
classify: 2,
|
||||||
keys: that.keyword,
|
keys: that.keyword,
|
||||||
recruitment: 1,
|
recruitment: 1,
|
||||||
},
|
}
|
||||||
(res) => {
|
|
||||||
console.log("res", res);
|
that.G.Post(that.api.job_list, jobConfig, (res) => {
|
||||||
if (res.recordCount == 0) {
|
console.log('res', res)
|
||||||
that.loading = false;
|
if (res.recordCount == 0) {
|
||||||
} else {
|
that.loading = false
|
||||||
that.loading = true;
|
} else {
|
||||||
}
|
that.loading = true
|
||||||
that.speed = res.recordCount;
|
}
|
||||||
that.jobQuery.isFinish = res.recordList.length;
|
that.speed = res.recordCount
|
||||||
res.recordList = that.G.toGetAddressv3(res.recordList);
|
that.jobQuery.isFinish = res.recordList.length
|
||||||
res.recordList = that.G.toGetAge(res.recordList);
|
res.recordList = that.G.toGetAddressv3(res.recordList)
|
||||||
res.recordList = that.G.yijobCopy(res.recordList);
|
res.recordList = that.G.toGetAge(res.recordList)
|
||||||
if ($type == "init") {
|
res.recordList = that.G.yijobCopy(res.recordList)
|
||||||
that.jobQuery.list = [];
|
if ($type == 'init') {
|
||||||
if (res.recordList.length > 0) {
|
that.jobQuery.list = []
|
||||||
that.jobQuery.list = res.recordList.map((item, index) => {
|
if (res.recordList.length > 0) {
|
||||||
// console.log(item)
|
that.jobQuery.list = res.recordList.map((item, index) => {
|
||||||
return {
|
// console.log(item)
|
||||||
...item,
|
return {
|
||||||
title: item.jobName,
|
...item,
|
||||||
address: item.district + "丨" + item.age,
|
title: item.jobName,
|
||||||
price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValue(item.salaryClassify, item.salaryClassifyValue) : that.G.getSalaryClassifyValue(item.salaryClassify, item.minMonthlyPay, item.maxMonthlyPay),
|
address: item.district + '丨' + item.age,
|
||||||
logo: item.agencyLogo,
|
price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValue(item.salaryClassify, item.salaryClassifyValue) : that.G.getSalaryClassifyValue(item.salaryClassify, item.minMonthlyPay, item.maxMonthlyPay),
|
||||||
fuWuFei: that.G.setReturnFee(item.returnFee, item.returnFeeType),
|
logo: item.agencyLogo,
|
||||||
gender: that.G.getGenderByMinAge(item),
|
fuWuFei: that.G.setReturnFee(item.returnFee, item.returnFeeType),
|
||||||
time: that.G.setDeadLine(item.updateTime, "jiaofu"),
|
gender: that.G.getGenderByMinAge(item),
|
||||||
leafCateId: item.id,
|
time: that.G.setDeadLine(item.updateTime, 'jiaofu'),
|
||||||
// serverPrice: that.G.setReturnFee(item.returnFee, item.returnFeeType),
|
leafCateId: item.id,
|
||||||
serverPrice: that.G.setReturnFee(item.agencyReturnFee, item.agencyReturnFeeType),
|
// serverPrice: that.G.setReturnFee(item.returnFee, item.returnFeeType),
|
||||||
recruitmentSwitch: item.recruitment == 1 ? true : false,
|
serverPrice: that.G.setReturnFee(item.agencyReturnFee, item.agencyReturnFeeType),
|
||||||
recruitmentImage: item.recruitment,
|
recruitmentSwitch: item.recruitment == 1 ? true : false,
|
||||||
isToday: item.today == 0 ? false : true,
|
recruitmentImage: item.recruitment,
|
||||||
active: 0,
|
isToday: item.today == 0 ? false : true,
|
||||||
};
|
active: 0,
|
||||||
});
|
}
|
||||||
}
|
})
|
||||||
} else {
|
}
|
||||||
that.jobQuery.list = that.jobQuery.list.concat(
|
} else {
|
||||||
res.recordList.map((item, index) => {
|
that.jobQuery.list = that.jobQuery.list.concat(
|
||||||
return {
|
res.recordList.map((item, index) => {
|
||||||
...item,
|
return {
|
||||||
title: item.jobName,
|
...item,
|
||||||
address: item.district + "丨" + item.age,
|
title: item.jobName,
|
||||||
price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValue(item.salaryClassify, item.salaryClassifyValue) : that.G.getSalaryClassifyValue(item.salaryClassify, item.minMonthlyPay, item.maxMonthlyPay),
|
address: item.district + '丨' + item.age,
|
||||||
logo: item.agencyLogo,
|
price: item.salaryClassify != 7 ? that.G.getSalaryClassifyValue(item.salaryClassify, item.salaryClassifyValue) : that.G.getSalaryClassifyValue(item.salaryClassify, item.minMonthlyPay, item.maxMonthlyPay),
|
||||||
fuWuFei: that.G.setReturnFee(item.returnFee, item.returnFeeType),
|
logo: item.agencyLogo,
|
||||||
gender: that.G.getGenderByMinAge(item),
|
fuWuFei: that.G.setReturnFee(item.returnFee, item.returnFeeType),
|
||||||
time: that.G.setDeadLine(item.updateTime, "jiaofu"),
|
gender: that.G.getGenderByMinAge(item),
|
||||||
leafCateId: item.id,
|
time: that.G.setDeadLine(item.updateTime, 'jiaofu'),
|
||||||
// serverPrice: that.G.setReturnFee(item.returnFee, item.returnFeeType),
|
leafCateId: item.id,
|
||||||
serverPrice: that.G.setReturnFee(item.agencyReturnFee, item.agencyReturnFeeType),
|
// serverPrice: that.G.setReturnFee(item.returnFee, item.returnFeeType),
|
||||||
recruitmentSwitch: item.recruitment == 1 ? true : false,
|
serverPrice: that.G.setReturnFee(item.agencyReturnFee, item.agencyReturnFeeType),
|
||||||
recruitmentImage: item.recruitment,
|
recruitmentSwitch: item.recruitment == 1 ? true : false,
|
||||||
isToday: item.today == 0 ? false : true,
|
recruitmentImage: item.recruitment,
|
||||||
active: 0,
|
isToday: item.today == 0 ? false : true,
|
||||||
};
|
active: 0,
|
||||||
})
|
}
|
||||||
);
|
})
|
||||||
}
|
)
|
||||||
if (that.whichPage == "record") {
|
}
|
||||||
that.jobQuery.list = that.jobQuery.list.filter((item) => {
|
if (that.whichPage == 'record') {
|
||||||
return item.recruitmentImage == 1;
|
that.jobQuery.list = that.jobQuery.list.filter((item) => {
|
||||||
});
|
return item.recruitmentImage == 1
|
||||||
that.speed = that.jobQuery.list.length;
|
})
|
||||||
}
|
that.speed = that.jobQuery.list.length
|
||||||
console.log("that.jobQuery.list", that.jobQuery.list);
|
}
|
||||||
console.log("speed", that.speed);
|
console.log('that.jobQuery.list', that.jobQuery.list)
|
||||||
// that.loading = false;
|
console.log('speed', that.speed)
|
||||||
}
|
// that.loading = false;
|
||||||
);
|
})
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 获取工单列表
|
* 获取工单列表
|
||||||
*/
|
*/
|
||||||
getApplyList($type = "init") {
|
getApplyList($type = 'init') {
|
||||||
let that = this;
|
let that = this
|
||||||
that.G.Post(
|
that.G.Post(
|
||||||
that.api.order_list_new,
|
that.api.order_list_new,
|
||||||
{
|
{
|
||||||
pageNum: that.jobQuery.page,
|
pageNum: that.jobQuery.page,
|
||||||
pageSize: that.jobQuery.size,
|
pageSize: that.jobQuery.size,
|
||||||
keys: that.keyword,
|
keys: that.keyword,
|
||||||
classify: that.applyType + 1,
|
classify: that.applyType + 1,
|
||||||
status: "",
|
status: '',
|
||||||
},
|
},
|
||||||
(res) => {
|
(res) => {
|
||||||
if (res.recordCount == 0) {
|
if (res.recordCount == 0) {
|
||||||
that.loading = false;
|
that.loading = false
|
||||||
} else {
|
} else {
|
||||||
that.loading = true;
|
that.loading = true
|
||||||
}
|
}
|
||||||
that.$forceUpdate();
|
that.$forceUpdate()
|
||||||
that.speed = res.recordCount;
|
that.speed = res.recordCount
|
||||||
that.jobQuery.isFinish = res.recordList.length;
|
that.jobQuery.isFinish = res.recordList.length
|
||||||
if (that.speed > 0) {
|
if (that.speed > 0) {
|
||||||
// uni.setBackgroundColor({
|
// uni.setBackgroundColor({
|
||||||
// backgroundColorBottom: "#ffffff",
|
// backgroundColorBottom: "#ffffff",
|
||||||
// });
|
// });
|
||||||
res.recordList.forEach((item, index) => {
|
res.recordList.forEach((item, index) => {
|
||||||
item.time = that.G.getPointTime(item.updateTime, "MM--DD HH:MM");
|
item.time = that.G.getPointTime(item.updateTime, 'MM--DD HH:MM')
|
||||||
item.status_text = that.G.getOrderStatus().filter((itm, inx) => {
|
item.status_text = that.G.getOrderStatus().filter((itm, inx) => {
|
||||||
return itm.id == item.status;
|
return itm.id == item.status
|
||||||
})[0].name;
|
})[0].name
|
||||||
item.setTitle = that.G.titleToStr(item);
|
item.setTitle = that.G.titleToStr(item)
|
||||||
});
|
})
|
||||||
} else {
|
} else {
|
||||||
// uni.setBackgroundColor({
|
// uni.setBackgroundColor({
|
||||||
// backgroundColorBottom: "#ededed",
|
// backgroundColorBottom: "#ededed",
|
||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
if ($type == "init") {
|
if ($type == 'init') {
|
||||||
that.jobQuery.list = res.recordList;
|
that.jobQuery.list = res.recordList
|
||||||
// that.query.list = [...res.recordList, ...res.recordList, ...res.recordList, ...res.recordList, ...res.recordList];
|
// that.query.list = [...res.recordList, ...res.recordList, ...res.recordList, ...res.recordList, ...res.recordList];
|
||||||
} else {
|
} else {
|
||||||
that.jobQuery.list = that.jobQuery.list.concat(res.recordList);
|
that.jobQuery.list = that.jobQuery.list.concat(res.recordList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="less"></style>
|
<style scoped lang="less"></style>
|
||||||
|
|||||||
@ -0,0 +1,126 @@
|
|||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
stopCount: 0,
|
||||||
|
renderjsData: {
|
||||||
|
url: "",
|
||||||
|
key: 0,
|
||||||
|
body: "",
|
||||||
|
method: ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
stopChat() {
|
||||||
|
this.stopCount += 1
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 开始chat对话
|
||||||
|
*/
|
||||||
|
startChat(config) {
|
||||||
|
const { body } = config;
|
||||||
|
this.renderjsData = Object.assign({}, this.renderjsData, {
|
||||||
|
key: this.renderjsData.key + 1,
|
||||||
|
...config,
|
||||||
|
body: body ? JSON.stringify(body) : 0,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
open(...args) {
|
||||||
|
this.$emit("onInnerOpen", ...args)
|
||||||
|
},
|
||||||
|
message(msg) {
|
||||||
|
this.$emit("onInnerMessage", msg)
|
||||||
|
},
|
||||||
|
error(...args) {
|
||||||
|
this.$emit("onInnerError", ...args)
|
||||||
|
this.stopChat();
|
||||||
|
},
|
||||||
|
finish() {
|
||||||
|
this.$emit("onInnerFinish")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script module="chat" lang="renderjs">
|
||||||
|
import { fetchEventSource } from '../fetch-event-source';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
ctrl: null,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
objToJson(obj) {
|
||||||
|
const json = {};
|
||||||
|
for (const key in obj) {
|
||||||
|
const val = obj[key];
|
||||||
|
if (typeof val === "string" || typeof val === 'number' || typeof val === 'boolean') {
|
||||||
|
json[key] = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 停止生成
|
||||||
|
*/
|
||||||
|
stopChatCore() {
|
||||||
|
this.ctrl?.abort();
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始对话
|
||||||
|
*/
|
||||||
|
startChatCore({ url, body, headers, method }) {
|
||||||
|
if (!url) return;
|
||||||
|
try {
|
||||||
|
this.ctrl = new AbortController();
|
||||||
|
fetchEventSource(
|
||||||
|
url,
|
||||||
|
{
|
||||||
|
readJson: true,
|
||||||
|
method,
|
||||||
|
openWhenHidden: true,
|
||||||
|
signal: this.ctrl.signal,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
...headers,
|
||||||
|
},
|
||||||
|
body: body ? body : undefined,
|
||||||
|
onopen: (response) => {
|
||||||
|
this.$ownerInstance.callMethod('open', this.objToJson(response));
|
||||||
|
},
|
||||||
|
onmessage: (data) => {
|
||||||
|
this.$ownerInstance.callMethod('message', data);
|
||||||
|
},
|
||||||
|
onerror: (err) => {
|
||||||
|
console.log(err)
|
||||||
|
this.$ownerInstance.callMethod('error', JSON.stringify(err));
|
||||||
|
},
|
||||||
|
}).then(() => {
|
||||||
|
this.$ownerInstance.callMethod('finish');
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
this.$ownerInstance.callMethod('error', err);
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<view
|
||||||
|
:renderjsData="renderjsData"
|
||||||
|
:change:renderjsData="chat.startChatCore"
|
||||||
|
:stopCount="stopCount"
|
||||||
|
:change:stopCount="chat.stopChatCore"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
<script>
|
||||||
|
import {getLines, getMessages} from "../fetch-event-source/parse"
|
||||||
|
|
||||||
|
let requestTask;
|
||||||
|
export default {
|
||||||
|
props: {},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
onChunk: undefined
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
const onLine = getMessages(() => {}, () => {}, (line) => {
|
||||||
|
this.$emit("onInnerMessage", line)
|
||||||
|
})
|
||||||
|
this.onChunk = getLines(onLine);
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
stopChat() {
|
||||||
|
requestTask.offChunkReceived(this.listener)
|
||||||
|
requestTask.abort();
|
||||||
|
},
|
||||||
|
|
||||||
|
decode(data) {
|
||||||
|
return decodeURIComponent(escape(String.fromCharCode(...data)));
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始chat对话
|
||||||
|
* @param body
|
||||||
|
* @param url
|
||||||
|
* @param headers
|
||||||
|
* @param method
|
||||||
|
*/
|
||||||
|
startChat({ body, url, headers, method }) {
|
||||||
|
requestTask = uni.request({
|
||||||
|
url: url,
|
||||||
|
method,
|
||||||
|
header: {
|
||||||
|
Accept: 'text/event-stream',
|
||||||
|
...headers,
|
||||||
|
},
|
||||||
|
data: body,
|
||||||
|
enableChunked: true,
|
||||||
|
responseType: 'arraybuffer',
|
||||||
|
success: (res) => {
|
||||||
|
},
|
||||||
|
fail: (error) => {
|
||||||
|
this.$emit("onInnerError", error)
|
||||||
|
},
|
||||||
|
complete: () => {
|
||||||
|
this.$emit("onInnerFinish")
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
requestTask.onChunkReceived(this.listener)
|
||||||
|
this.$emit("onInnerOpen", requestTask)
|
||||||
|
},
|
||||||
|
|
||||||
|
listener({ data }) {
|
||||||
|
const type = Object.prototype.toString.call(data);
|
||||||
|
if (type ==="[object Uint8Array]") {
|
||||||
|
} else if (data instanceof ArrayBuffer) {
|
||||||
|
data = new Uint8Array(data);
|
||||||
|
}
|
||||||
|
this.onChunk(data)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<view />
|
||||||
|
</template>
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
var __rest = (this && this.__rest) || function (s, e) {
|
||||||
|
var t = {};
|
||||||
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||||
|
t[p] = s[p];
|
||||||
|
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||||
|
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||||
|
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
||||||
|
t[p[i]] = s[p[i]];
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
};
|
||||||
|
import { getBytes, getLines, getMessages } from './parse';
|
||||||
|
export const EventStreamContentType = 'text/event-stream';
|
||||||
|
const DefaultRetryInterval = 1000;
|
||||||
|
const LastEventId = 'last-event-id';
|
||||||
|
export function fetchEventSource(input, _a) {
|
||||||
|
var { signal: inputSignal, headers: inputHeaders, onopen: inputOnOpen, onmessage, onclose, onerror, openWhenHidden, fetch: inputFetch } = _a, rest = __rest(_a, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const headers = Object.assign({}, inputHeaders);
|
||||||
|
if (!headers.accept) {
|
||||||
|
headers.accept = EventStreamContentType;
|
||||||
|
}
|
||||||
|
let curRequestController;
|
||||||
|
function onVisibilityChange() {
|
||||||
|
curRequestController.abort();
|
||||||
|
if (!document.hidden) {
|
||||||
|
create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!openWhenHidden) {
|
||||||
|
document.addEventListener('visibilitychange', onVisibilityChange);
|
||||||
|
}
|
||||||
|
let retryInterval = DefaultRetryInterval;
|
||||||
|
let retryTimer = 0;
|
||||||
|
function dispose() {
|
||||||
|
document.removeEventListener('visibilitychange', onVisibilityChange);
|
||||||
|
window.clearTimeout(retryTimer);
|
||||||
|
curRequestController.abort();
|
||||||
|
}
|
||||||
|
inputSignal === null || inputSignal === void 0 ? void 0 : inputSignal.addEventListener('abort', () => {
|
||||||
|
dispose();
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
const fetch = inputFetch !== null && inputFetch !== void 0 ? inputFetch : window.fetch;
|
||||||
|
const onopen = inputOnOpen !== null && inputOnOpen !== void 0 ? inputOnOpen : defaultOnOpen;
|
||||||
|
async function create() {
|
||||||
|
var _a;
|
||||||
|
curRequestController = new AbortController();
|
||||||
|
try {
|
||||||
|
const response = await fetch(input, Object.assign(Object.assign({}, rest), { headers, signal: curRequestController.signal }));
|
||||||
|
await onopen(response);
|
||||||
|
await getBytes(response.body, getLines(getMessages(id => {
|
||||||
|
if (id) {
|
||||||
|
headers[LastEventId] = id;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
delete headers[LastEventId];
|
||||||
|
}
|
||||||
|
}, retry => {
|
||||||
|
retryInterval = retry;
|
||||||
|
}, onmessage)));
|
||||||
|
onclose === null || onclose === void 0 ? void 0 : onclose();
|
||||||
|
dispose();
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
if (!curRequestController.signal.aborted) {
|
||||||
|
try {
|
||||||
|
const interval = (_a = onerror === null || onerror === void 0 ? void 0 : onerror(err)) !== null && _a !== void 0 ? _a : retryInterval;
|
||||||
|
window.clearTimeout(retryTimer);
|
||||||
|
retryTimer = window.setTimeout(create, interval);
|
||||||
|
}
|
||||||
|
catch (innerErr) {
|
||||||
|
dispose();
|
||||||
|
reject(innerErr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
create();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function defaultOnOpen(response) {
|
||||||
|
const contentType = response.headers.get('content-type');
|
||||||
|
if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith(EventStreamContentType))) {
|
||||||
|
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=fetch.js.map
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
export { fetchEventSource, EventStreamContentType } from './fetch';
|
||||||
|
//# sourceMappingURL=index.js.map
|
||||||
@ -0,0 +1,128 @@
|
|||||||
|
export async function getBytes(stream, onChunk) {
|
||||||
|
const reader = stream.getReader();
|
||||||
|
let result;
|
||||||
|
while (!(result = await reader.read()).done) {
|
||||||
|
onChunk(result.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export function getLines(onLine) {
|
||||||
|
let buffer;
|
||||||
|
let position;
|
||||||
|
let fieldLength;
|
||||||
|
let discardTrailingNewline = false;
|
||||||
|
return function onChunk(arr) {
|
||||||
|
if (buffer === undefined) {
|
||||||
|
buffer = arr;
|
||||||
|
position = 0;
|
||||||
|
fieldLength = -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
buffer = concat(buffer, arr);
|
||||||
|
}
|
||||||
|
const bufLength = buffer.length;
|
||||||
|
let lineStart = 0;
|
||||||
|
while (position < bufLength) {
|
||||||
|
if (discardTrailingNewline) {
|
||||||
|
if (buffer[position] === 10) {
|
||||||
|
lineStart = ++position;
|
||||||
|
}
|
||||||
|
discardTrailingNewline = false;
|
||||||
|
}
|
||||||
|
let lineEnd = -1;
|
||||||
|
for (; position < bufLength && lineEnd === -1; ++position) {
|
||||||
|
switch (buffer[position]) {
|
||||||
|
case 58:
|
||||||
|
if (fieldLength === -1) {
|
||||||
|
fieldLength = position - lineStart;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 13:
|
||||||
|
discardTrailingNewline = true;
|
||||||
|
case 10:
|
||||||
|
lineEnd = position;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (lineEnd === -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
||||||
|
lineStart = position;
|
||||||
|
fieldLength = -1;
|
||||||
|
}
|
||||||
|
if (lineStart === bufLength) {
|
||||||
|
buffer = undefined;
|
||||||
|
}
|
||||||
|
else if (lineStart !== 0) {
|
||||||
|
buffer = buffer.subarray(lineStart);
|
||||||
|
position -= lineStart;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export function getMessages(onId, onRetry, onMessage) {
|
||||||
|
let message = newMessage();
|
||||||
|
let decoder;
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
decoder = {
|
||||||
|
decode(arraybuffer) {
|
||||||
|
return decodeURIComponent(escape(String.fromCharCode(...arraybuffer)))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef APP-PLUS || H5
|
||||||
|
decoder = new TextDecoder();
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
return function onLine(line, fieldLength) {
|
||||||
|
if (line.length === 0) {
|
||||||
|
onMessage === null || onMessage === void 0 ? void 0 : onMessage(message);
|
||||||
|
message = newMessage();
|
||||||
|
}
|
||||||
|
else if (fieldLength > 0) {
|
||||||
|
const field = decoder.decode(line.subarray(0, fieldLength));
|
||||||
|
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 ? 2 : 1);
|
||||||
|
const value = decoder.decode(line.subarray(valueOffset));
|
||||||
|
switch (field) {
|
||||||
|
case 'data':
|
||||||
|
message.data = message.data
|
||||||
|
? message.data + '\n' + value
|
||||||
|
: value;
|
||||||
|
break;
|
||||||
|
case 'event':
|
||||||
|
message.event = value;
|
||||||
|
break;
|
||||||
|
case 'id':
|
||||||
|
onId(message.id = value);
|
||||||
|
break;
|
||||||
|
case 'retry':
|
||||||
|
const retry = parseInt(value, 10);
|
||||||
|
if (!isNaN(retry)) {
|
||||||
|
onRetry(message.retry = retry);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
const msg = decoder.decode(line, { stream: true });
|
||||||
|
message.data = msg
|
||||||
|
onMessage(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function concat(a, b) {
|
||||||
|
const res = new Uint8Array(a.length + b.length);
|
||||||
|
res.set(a);
|
||||||
|
res.set(b, a.length);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
function newMessage() {
|
||||||
|
return {
|
||||||
|
data: '',
|
||||||
|
event: '',
|
||||||
|
id: '',
|
||||||
|
retry: undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=parse.js.map
|
||||||
@ -0,0 +1,58 @@
|
|||||||
|
<template>
|
||||||
|
<!-- #ifdef MP-WEIXIN-->
|
||||||
|
<ChatWxApplet ref="chatRef" @onInnerOpen="open" @onInnerError="error" @onInnerMessage="message" @onInnerFinish="finish" />
|
||||||
|
<!-- #endif-->
|
||||||
|
|
||||||
|
<!-- #ifdef APP-PLUS || H5-->
|
||||||
|
<ChatAppAndWeb ref="chatRef" @onInnerOpen="open" @onInnerError="error" @onInnerMessage="message" @onInnerFinish="finish" />
|
||||||
|
<!-- #endif-->
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
import ChatWxApplet from "./children/ChatWxApplet.vue";
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef APP-PLUS || H5
|
||||||
|
import ChatAppAndWeb from "./children/ChatAppAndWeb.vue";
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
ChatWxApplet,
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef APP-PLUS || H5
|
||||||
|
ChatAppAndWeb,
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
startChat(config) {
|
||||||
|
config["method"] = (config["method"] || "post").toUpperCase();
|
||||||
|
config["headers"] = config["headers"] || {};
|
||||||
|
console.log("this.$refs['chatRef']", this.$refs["chatRef"]);
|
||||||
|
this.$refs["chatRef"].startChat(config);
|
||||||
|
},
|
||||||
|
|
||||||
|
stopChat(...args) {
|
||||||
|
console.log("this.$refs['chatRef']stopChat", this.$refs["chatRef"]);
|
||||||
|
this.$refs["chatRef"].stopChat(...args);
|
||||||
|
},
|
||||||
|
|
||||||
|
open(...args) {
|
||||||
|
this.$emit("onOpen", ...args);
|
||||||
|
},
|
||||||
|
message(msg) {
|
||||||
|
this.$emit("onMessage", msg);
|
||||||
|
},
|
||||||
|
error(...args) {
|
||||||
|
this.$emit("onError", ...args);
|
||||||
|
},
|
||||||
|
finish() {
|
||||||
|
this.$emit("onFinish");
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
Loading…
Reference in New Issue