Vue.component("http-cache-refs-config-box", { props: ["v-cache-refs"], mounted: function () { let that = this sortTable(function (ids) { let newRefs = [] ids.forEach(function (id) { that.refs.forEach(function (ref) { if (ref.id == id) { newRefs.push(ref) } }) }) that.refs = newRefs }) }, data: function () { let refs = this.vCacheRefs if (refs == null) { refs = [] } let id = 0 refs.forEach(function (ref) { id++ ref.id = id }) return { refs: refs, id: id // 用来对条件进行排序 } }, methods: { addRef: function (isReverse) { window.UPDATING_CACHE_REF = null let width = window.innerWidth if (width > 1024) { width = 1024 } let height = window.innerHeight if (height > 500) { height = 500 } let that = this teaweb.popup("/servers/server/settings/cache/createPopup?isReverse=" + (isReverse ? 1 : 0), { width: width + "px", height: height + "px", callback: function (resp) { that.id++ resp.data.cacheRef.id = that.id that.refs.push(resp.data.cacheRef) } }) }, updateRef: function (index, cacheRef) { window.UPDATING_CACHE_REF = cacheRef let width = window.innerWidth if (width > 1024) { width = 1024 } let height = window.innerHeight if (height > 500) { height = 500 } let that = this teaweb.popup("/servers/server/settings/cache/createPopup", { width: width + "px", height: height + "px", callback: function (resp) { resp.data.cacheRef.id = that.refs[index].id Vue.set(that.refs, index, resp.data.cacheRef) // 通知子组件更新 that.$refs.cacheRef[index].notifyChange() } }) }, removeRef: function (index) { let that = this teaweb.confirm("确定要删除此缓存设置吗?", function () { that.refs.$remove(index) }) }, timeUnitName: function (unit) { switch (unit) { case "ms": return "毫秒" case "second": return "秒" case "minute": return "分钟" case "hour": return "小时" case "day": return "天" case "week": return "周 " } return unit } }, template: `
` })