widget/Container.php
public function code(Field $field, $attr = [])
    {
        $field->mode = empty($field->mode) ? 'single' : $field->mode;
        #单一模式
        if ($field->mode == 'single') {
            $attr['type'] = '';
            $attr['name'] = '';
            $attr['value'] = '';
            $attr['class'] = '';
            $attr['id'] = 'row_' . $field->boxId;
            $attr = WidgetHelper::mergeAttributes($field, $attr);
            if (empty($field->plugName)) {
                return '<div ' . join(' ', $attr) . '></div>';
            }
            $form = self::plugForm($field);
            if (empty($form->template)) {
                throw new \Exception('插件模板不存在');
            }
            $viewer = new View();
            $viewer->fetch($form->template);
            $wrapFunc = $viewer->getHook('single');
            if ($wrapFunc == null) {
                throw new \Exception('模板中没有找到 {hook fn="single"} 的钩子函数');
            }
            $tinker = $field->getFunc('tinker');
            if ($tinker && is_callable($tinker)) {
                call_user_func($tinker, $form);
            }
            $form->setValues($field->value);
            self::perfect($field, $form);
            $code = $wrapFunc(['field' => $field, 'form' => $form]);
            return '<div ' . join(' ', $attr) . '>' . $code . '</div>';
        } else {
            #多增模式
            if (empty($field->plugName)) {
                return '';
            }
            $form = self::plugForm($field, 'add');
            if (empty($form->template)) {
                throw new \Exception('插件模板不存在');
            }
            $viewer = new View();
            $viewer->fetch($form->template);
            $wrapFunc = $viewer->getHook('multiple-wrap');
            $itemFunc = $viewer->getHook('multiple-item');
            if ($wrapFunc == null) {
                throw new \Exception('模板中没有找到 {hook fn="multiple-wrap"} 的钩子函数');
            }
            if ($itemFunc == null) {
                throw new \Exception('模板中没有找到 {hook fn="multiple-item"} 的钩子函数');
            }
            $out = [];
            $values = $field->value;
            $index = 0;
            $tinker = $field->getFunc('tinker');
            if (!empty($values) && is_array($values)) {
                foreach ($values as $idx => $item) {
                    $pForm = self::plugForm($field, 'edit');
                    if ($tinker && is_callable($tinker)) {
                        call_user_func($tinker, $pForm);
                    }
                    $pForm->setValues($item);
                    self::perfect($field, $pForm, $index);
                    $code = $itemFunc(['field' => $field, 'form' => $pForm, 'index' => 'a' . $index]);
                    $out[] = $code;
                    $index++;
                }
            }
            if ($tinker && is_callable($tinker)) {
                call_user_func($tinker, $form);
            }
            self::perfect($field, $form);
            $code = $itemFunc(['field' => $field, 'form' => $form, 'index' => '@@index@@']);
            $data = [];
            $data[] = 'data-index="' . htmlspecialchars($index) . '"';
            if ($field->dataMinSize) {
                $data[] = 'data-min-size="' . $field->dataMinSize . '"';
            }
            if ($field->dataMaxSize) {
                $data[] = 'data-max-size="' . $field->dataMaxSize . '"';
            }
            if ($field->dataInitSize) {
                $data[] = 'data-init-size="' . $field->dataInitSize . '"';
            }
            return $wrapFunc([
                'field' => $field,
                'form' => $form,
                'body' => join('', $out),
                'source' => base64_encode($code),
                'lastIndex' => $index,
                'attrs' => join(' ', $data)
            ]);
        }
    }
public function code(Field $field, $attr = [])
    {
        $field->mode = empty($field->mode) ? 'single' : $field->mode;
        #单一模式
        if ($field->mode == 'single') {
            $attr['type'] = '';
            $attr['name'] = '';
            $attr['value'] = '';
            $attr['class'] = '';
            $attr['id'] = 'row_' . $field->boxId;
            $attr = WidgetHelper::mergeAttributes($field, $attr);
            if (empty($field->plugName)) {
                return '<div ' . join(' ', $attr) . '></div>';
            }
            $form = self::plugForm($field);
            if (empty($form->template)) {
                throw new \Exception('插件模板不存在');
            }
            $viewer = new View();
            $viewer->fetch($form->template);
            $wrapFunc = $viewer->getHook('single');
            if ($wrapFunc == null) {
                throw new \Exception('模板中没有找到 {hook fn="single"} 的钩子函数');
            }
            $tinker = $field->getFunc('tinker');
            if ($tinker && is_callable($tinker)) {
                call_user_func($tinker, $form);
            }
            $form->setValues($field->value);
            self::perfect($field, $form);
            $code = $wrapFunc(['field' => $field, 'form' => $form]);
            return '<div ' . join(' ', $attr) . '>' . $code . '</div>';
        } else {
            #多增模式
            if (empty($field->plugName)) {
                return '';
            }
            $form = self::plugForm($field, 'add');
            if (empty($form->template)) {
                throw new \Exception('插件模板不存在');
            }
            $viewer = new View();
            $viewer->fetch($form->template);
            $wrapFunc = $viewer->getHook('multiple-wrap');
            $itemFunc = $viewer->getHook('multiple-item');
            if ($wrapFunc == null) {
                throw new \Exception('模板中没有找到 {hook fn="multiple-wrap"} 的钩子函数');
            }
            if ($itemFunc == null) {
                throw new \Exception('模板中没有找到 {hook fn="multiple-item"} 的钩子函数');
            }
            $out = [];
            $values = $field->value;
            $index = 0;
            $tinker = $field->getFunc('tinker');
            if (!empty($values) && is_array($values)) {
                foreach ($values as $idx => $item) {
                    $pForm = self::plugForm($field, 'edit');
                    if ($tinker && is_callable($tinker)) {
                        call_user_func($tinker, $pForm);
                    }
                    $pForm->setValues($item);
                    self::perfect($field, $pForm, $index);
                    $code = $itemFunc(['field' => $field, 'form' => $pForm, 'index' => 'a' . $index]);
                    $out[] = $code;
                    $index++;
                }
            }
            if ($tinker && is_callable($tinker)) {
                call_user_func($tinker, $form);
            }
            self::perfect($field, $form);
            $code = $itemFunc(['field' => $field, 'form' => $form, 'index' => '@@index@@']);
            $data = [];
            $data[] = 'data-index="' . htmlspecialchars($index) . '"';
            if ($field->dataMinSize) {
                $data[] = 'data-min-size="' . $field->dataMinSize . '"';
            }
            if ($field->dataMaxSize) {
                $data[] = 'data-max-size="' . $field->dataMaxSize . '"';
            }
            if ($field->dataInitSize) {
                $data[] = 'data-init-size="' . $field->dataInitSize . '"';
            }
            return $wrapFunc([
                'field' => $field,
                'form' => $form,
                'body' => join('', $out),
                'source' => base64_encode($code),
                'lastIndex' => $index,
                'attrs' => join(' ', $data)
            ]);
        }
    }
生成代码
@param Field $field
@param array $attr
@return string
@throws \Exception