c语言combine函数,自定义组件(原创)——组合Ccombine

本组件中使用到了iview的Icon,可以在全局安装了Iview的项目或者局部引入了Icon的页面中自由使用。目录效果展示

bVcQxpw

从左到右分别是:未选中状态、鼠标悬浮、选中、添加组合按钮功能描述添加/删除组合

单击聚焦组合

双击修改组合名字

切换下一个组合或者新增组合时上一个组合内容固定

组合不能清空,可以设置组合数量上限结构代码

{{item.name}}

+添加

根据edit确定编辑状态还是文本显示状态

selected确定选中状态还是未选中状态逻辑代码// 输入组合名字

name_input (idx) {

// console.log('聚焦')

},

// 组合名字输入完毕

input_over (idx, name) {

this.com_arr[idx].edit = false

// console.log('失焦')

this.$emit('changename', idx, name)

this.$emit('synfun', this.com_arr)

},

name_click (_type, idx) {

var self = this

clearTimeout(this.timer)

if (_type === 1) { // 单击某个组合

if (event.detail === 2) return

this.timer = setTimeout(function () {

// console.log('单击')

let last_sel_id = 0

if (isArray(self.com_arr)) {

self.com_arr.forEach(com => {

if (com.selected)last_sel_id = com.id

com.edit = false

com.selected = false

})

self.com_arr[idx].selected = true

self.$emit('fixfun', 'click', last_sel_id, idx)

}

}, 100)

} else {

// console.log('双击')

this.com_arr[idx].edit = true

}

this.$emit('synfun', this.com_arr)

},

// 选中某个组合

selcom_handle (idx) {

if (isArray(this.com_arr)) {

let last_sel_id = 0

this.com_arr.forEach(com => {

if (com.selected)last_sel_id = com.id

com.selected = false

})

this.com_arr[idx].selected = true

this.$emit('synfun', this.com_arr)

this.$emit('fixfun', 'click', last_sel_id, idx)

}

},

// 删除某个组合

close_com (idx) {

if (this.com_arr.length === 1) {

this.$Message.warning('组合不能清空哦-_-')

} else {

alert('删除' + (idx + 1) + 'id: ' + this.com_arr[idx].id)

let cur_idx = 999

if (this.com_arr[idx].selected) {

this.com_arr.splice(idx, 1)

this.com_arr[0].selected = true

cur_idx = 0

} else {

this.com_arr.splice(idx, 1)

}

this.$emit('synfun', this.com_arr)

this.$emit('delfun', idx, cur_idx)

}

},

// 新增组合

addcom_handle () {

if (this.com_arr.length === this.max_com) {

this.$Message.warning('最多只能添加5个组合~.~')

} else if (isArray(this.com_arr)) {

let last_sel_id = 0

this.com_arr.forEach(com => {

if (com.selected)last_sel_id = com.id

com.selected = false

com.edit = false

})

const id_temp = genID(1)

const addcom = {

name: '双击命名',

content: {},

id: id_temp,

selected: true,

edit: true

}

this.com_arr.push(addcom)

this.$emit('synfun', this.com_arr)

this.$emit('fixfun', 'add', last_sel_id, addcom)

}

}处理新增组合事件

删除某个组合事件

选中某个组合事件

单击或双击某个组合事件(单击选中/双击改名)

输入组合名结束事件组件应用

:com_arr="com_arr"

:max_com="max_com"

@synfun="syn_handle"

@fixfun="fix_handle"

@delfun="del_handle"

@changename="changename_handle"

/>

import Ccombine from '@/components/c-combine/index.vue'

components: {

Ccombine

}

data () {

return {

max_com: 5, // 组合最大数量

com_arr: [{ // 默认组合

name: '组合6',

content: {},

id: 0,

selected: true,

edit: false

}]

}

}import引入——>组件注册——>使用

父——>子传参:com_arr初始组合、max_com组合的最大数量事件钩子syn_handle (newValue) {

this.com_arr = newValue

},

// 上一个组合内容固定

fix_handle (motion, last_sel_id, param) {

// motion:动作'add'/'click'新增或者切换

// last_sel_id:上一个聚焦的组合id

// param:'add'对应addcom/'click'对应cur_idx

},

// 删除某个组合

del_handle (idx, cur_idx) {

// idx:删除的组合index,cur_idx删除的组合Index

},

// 组合改名字

changename_handle (idx, name) {

// idx:修改名字组合的idx,name:修改后的新组合名

}syn_handle:同步处理,子组件里的组合更改同步到父组件

fix_handle:固定组合内容处理,新增或者切换的时候固定上一个组合的content

del_handle:删除某个组合

changename_handle:组合改名字github

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使combine函数能够装载任意多的函数,我们可以使用可变参数模板。具体实现如下: ```cpp template <typename F, typename... Fs, typename T> auto combine(F f, Fs... fs) { auto rest = combine(fs...); return [=](T x) { return f(rest(x)); }; } ``` 在这个实现中,我们首先定义了一个combine函数模板,它接收至少一个函数f和任意数量的函数fs作为参数,以及一个输入类型T。然后,我们使用可变参数模板来递归调用combine函数,将剩余的函数fs拆分成一个个单独的函数,并将它们作为参数传递给rest。最后,我们返回一个lambda函数,它接收一个输入值x,并将它依次传递给所有函数,最终返回最后一个函数的输出值。 使用这个新的combine函数模板,我们可以将任意数量的函数组合成一个新的函数。例如,我们可以定义三个简单的函数: ```cpp auto square = [](double x) { return x * x; }; auto inc = [](double x) { return x + 1; }; auto half = [](double x) { return x / 2; }; ``` 然后,我们可以使用combine函数将它们组合成一个新的函数: ```cpp auto k = combine(square, inc, half); std::cout << k(4) << std::endl; // 输出23.5 ``` 在这个例子中,我们首先定义了三个简单的函数square、inc和half,然后使用combine函数将它们组合成一个新的函数k。当我们调用k(4)时,它首先将4平方为16,然后将结果加1得到17,最后将结果除以2得到23.5,即k(4) = half(inc(square(4))) = half(inc(16)) = half(17) = 23.5。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值