diff --git a/src/views/customerService/index.vue b/src/views/customerService/index.vue
index 321adb6..84b662e 100644
--- a/src/views/customerService/index.vue
+++ b/src/views/customerService/index.vue
@@ -50,8 +50,8 @@
@@ -333,7 +333,7 @@ const handleDelete = (item, index) => {
}
)
.then(async () => {
-
+
await deleteRobot({
ids: String(item.id)
})
@@ -364,13 +364,15 @@ let robot_data = ''
const tableLoading = ref(false)
let appSelects = []
const appTableRef = ref(null)
-
+let isInitializing = false // 标记是否正在初始化
const bandAppIds = ref([])
// 设置已绑定小程序的选中状态
const setSelectedApps = () => {
+ isInitializing = true // 设置初始化标志,防止appSelectionChange错误更新
nextTick(() => {
+ console.log(bandAppIds.value)
if (appTableRef.value && logList.value.length > 0) {
logList.value.forEach(row => {
if (bandAppIds.value.includes(row.id)) {
@@ -378,35 +380,56 @@ const setSelectedApps = () => {
}
})
}
+ // 设置完成后,确保appSelects包含所有已绑定的ID(不仅仅是当前页的)
+ appSelects = [...new Set([...appSelects, ...bandAppIds.value])]
+ isInitializing = false // 初始化完成
})
}
-const openLog = async () => {
- dialogLog.value = true
+// const openLog = async () => {
+// dialogLog.value = true
+// appSelects = []
+// getApps()
+// getActApps()
+
+
+// }
+
+const getApps = async () => {
tableLoading.value = true
- const res = await appList(logQuery)
- logList.value = res.list
- total.value = res.total
-
- // 只在第一次打开时获取已绑定的小程序列表
- if (bandAppIds.value.length === 0 || logQuery.page === 1) {
- const res2 = await appList({
- admin_id: robot_data.id,
- page: 1,
- page_size: 100
- })
- tableLoading.value = false
-
- bandAppIds.value = res2.list.map(item => item.id)
- // 初始化 appSelects 包含已绑定的小程序
- appSelects = [...bandAppIds.value]
- }
-
- // 默认选中已绑定的小程序
- setSelectedApps()
+ const res = await appList(logQuery).then(res => {
+ logList.value = res.list
+ total.value = res.total
+ tableLoading.value = false
+ return res
+ }).catch(() => {
+ tableLoading.value = false
+ return null
+ })
+ return res
}
-const handleBindApp = (row) => {
+const getActApps = async () => {
+ tableLoading.value = true
+ const res2 = await appList({
+ admin_id: robot_data.id,
+ page: 1,
+ page_size: 100
+ }).then(res => {
+ bandAppIds.value = res.list.map(item => item.id)
+ // 初始化 appSelects 包含已绑定的小程序
+ console.log(bandAppIds.value)
+ console.log(appSelects)
+ appSelects = [...bandAppIds.value]
+ tableLoading.value = false
+ return res
+ }).catch(() => {
+ tableLoading.value = false
+ return null
+ })
+ return res2
+}
+const handleBindApp = async (row) => {
robot_data = row
dialogLog.value = true
logQuery.page = 1
@@ -420,7 +443,11 @@ const handleBindApp = (row) => {
appTableRef.value.clearSelection()
}
})
- openLog()
+ // 先加载小程序列表,再加载已绑定列表,最后设置选中状态
+ await getApps()
+ await getActApps()
+ // 数据加载完成后再设置选中状态(setSelectedApps内部会处理isInitializing标志)
+ setSelectedApps()
}
const isSelectable = (row) => {
@@ -431,20 +458,38 @@ const isSelectable = (row) => {
const appSelectionChange = (e) => {
// 获取当前选中的小程序ID
const selectedIds = e.map(item => item.id)
- // 合并已绑定的小程序ID,确保已绑定的小程序始终在选中列表中
- appSelects = [...new Set([...bandAppIds.value, ...selectedIds])]
+
+ // 如果不是初始化阶段,才处理取消勾选的逻辑
+ if (!isInitializing) {
+ // 找出被取消勾选的已绑定项目,从bandAppIds中移除
+ bandAppIds.value.forEach(id => {
+ if (!selectedIds.includes(id)) {
+ // 如果这个已绑定的ID不在当前选中列表中,说明被取消了,从bandAppIds中移除
+ const index = bandAppIds.value.indexOf(id)
+ if (index > -1) {
+ bandAppIds.value.splice(index, 1)
+ }
+ }
+ })
+ }
+
+ // appSelects 保存当前选中的所有ID(包括未取消的已绑定项和新选中的项)
+ appSelects = selectedIds
}
const saveBind = (val) => {
-
- if (appSelects.length == 0) {
+ // 合并已选列表和已绑定列表
+ const finalIds = [...new Set([...appSelects, ...bandAppIds.value])]
+ console.log(finalIds)
+ // return
+ if (finalIds.length == 0) {
ElNotification({
message: '请选择小程序',
type: 'warning'
})
} else {
bindApps(robot_data.id, {
- ids: appSelects.join(',')
+ ids: finalIds.join(',')
}).then(res => {
dialogLog.value = false
ElNotification({
@@ -455,14 +500,27 @@ const saveBind = (val) => {
}
}
-const handleSizeChange = (e) => {
+const sizeChange = (e) => {
+ query.page = 1
+ query.page_size = e
+ getTable()
+}
+const currentChange = (e) => {
+ query.page = e
+ getTable()
+}
+const handleSizeChange = async (e) => {
logQuery.page = 1
logQuery.page_size = e
- openLog()
+ await getApps()
+ // 翻页后重新设置选中状态
+ setSelectedApps()
}
-const handleCurrentChange = (e) => {
+const handleCurrentChange = async (e) => {
logQuery.page = e
- openLog()
+ await getApps()
+ // 翻页后重新设置选中状态
+ setSelectedApps()
}
const rowClassname = (e) => {