kevin_zhangl 3 лет назад
Родитель
Сommit
a7abf18edf

+ 1 - 0
backendApi/config/urlManagerRules.php

@@ -503,6 +503,7 @@ return [
             'POST category-add' => 'category-add',
             'GET,POST category-delete' => 'category-delete',
             'GET category-sort' => 'category-sort',
+            'POST upload' => 'upload',
         ],
     ],
     [

+ 28 - 0
backendApi/modules/v1/controllers/ArticleController.php

@@ -7,11 +7,15 @@
  */
 namespace backendApi\modules\v1\controllers;
 
+use common\helpers\Cache;
+use common\helpers\Form;
 use common\models\Article;
 use common\models\ArticleCategory;
 use common\models\forms\ArticleCategoryForm;
 use common\models\forms\ArticleForm;
+use common\models\forms\UploadForm;
 use Yii;
+use yii\web\UploadedFile;
 
 class ArticleController extends BaseController
 {
@@ -163,4 +167,28 @@ class ArticleController extends BaseController
             return static::notice('Article not exists!', 400); // 文章不存在
         }
     }
+
+    /**
+     * 上传图片
+     * @return mixed
+     * @throws \yii\base\Exception
+     * @throws \yii\db\Exception
+     * @throws \yii\web\HttpException
+     */
+    public function actionUpload() {
+        if (\Yii::$app->request->isPost) {
+            $formModel = new UploadForm();
+            $formModel->scenario = 'article';
+            $formModel->file = UploadedFile::getInstanceByName('file');
+            $formModel->token = \Yii::$app->request->request('uploadToken');;
+            if($formModel->file && $uploader = $formModel->upload()){
+                return static::notice($uploader->URL);
+            } else {
+                return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
+            }
+        } else {
+            $token = Cache::setUploadToken();
+            return static::notice($token);
+        }
+    }
 }

+ 26 - 2
backendEle/src/utils/editor.js

@@ -1,7 +1,10 @@
 import {CDN_IMG_URL} from './config'
+import network from "./network";
+import {SERVER_API_HTTP_TYPE,SERVER_API_DOMAIN} from '@/utils/config'
 
 const EDITOR_ROOT_URL = `${CDN_IMG_URL}/tinymce`
 const EDITOR_LANGUAGE = `${EDITOR_ROOT_URL}/langs/zh_CN.js`
+
 let fullEditor = {
   // language_url: EDITOR_LANGUAGE,
   height: 500,
@@ -16,9 +19,30 @@ let textEditor = {
   plugins: [
     'advlist autolink lists link charmap print preview anchor textcolor colorpicker',
     'searchreplace visualblocks code fullscreen',
-    'insertdatetime media table contextmenu paste code help'
+    'insertdatetime media table contextmenu paste image  code help'
   ],
-  toolbar: 'undo redo |  formatselect | bold italic backcolor forecolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | help'
+  toolbar: 'undo redo |  formatselect | bold italic backcolor forecolor | link image  | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | preview | help',
+  automatic_uploads: false,
+  image_title: false,
+  image_description: false,
+  images_upload_base_path: 'ad',
+  images_upload_handler: (blobInfo, success, failure) => {
+      const handler = async () => {
+          let token = await network.getData('file/token');
+
+          let params = new FormData()
+          params.append('file', blobInfo.blob())
+          params.append('uploadToken', token)
+          await network.postData('ad/upload', params).then(response => {
+              let imageUrl = SERVER_API_HTTP_TYPE + SERVER_API_DOMAIN + '/uploads/' + response;
+              success(imageUrl)
+          }).catch(error => {
+              failure(error)
+          })
+      }
+
+      handler();
+  },
 }
 
 export {

+ 2 - 9
backendEle/src/utils/tool.js

@@ -2,8 +2,8 @@ import errorCode from './errorCode'
 import baseInfo from './baseInfo'
 import userInfo from './userInfo'
 import router from '@/router'
-import {PRICE_IS_ROUND,SERVER_API_DOMAIN} from './config'
-import ElementUI from 'element-ui'
+import network from '@/utils/network'
+import {PRICE_IS_ROUND, SERVER_API_DOMAIN} from './config'
 
 let tool = {
   /**
@@ -262,13 +262,6 @@ let tool = {
       window.location.href = window.location.href.replace(searchStr, '$1$2'+value+'$4')
     }
   },
-
-  imageRenderSoup(cover) {
-    return cover.indexOf(SERVER_API_DOMAIN) > 0
-  },
-  imageRenderLang(cover) {
-    return SERVER_API_DOMAIN + '/uploads/' + cover
-  }
 }
 
 export default tool

+ 1 - 6
backendEle/src/views/ad/list.vue

@@ -5,12 +5,7 @@
                 @selection-change="handleSelectionChange" @row-click="handleExpand">
         <el-table-column type="expand">
           <template slot-scope="scope">
-            <a v-if="scope.row.TYPE === '1'" :href="getHref(scope.row.CONTENT)" target="_blank" class="islide">
-                <img :src="getImage(scope.row.IMAGE)" width="100px" height="100px" :alt="scope.row.TITLE">
-            </a>
-            <router-link v-else :to="`/article/detail/${scope.row.CONTENT}`" target="_blank" class="islide">
-                <img :src="getImage(scope.row.IMAGE)" width="100px" height="100px" :alt="scope.row.TITLE">
-            </router-link>
+              <img :src="getImage(scope.row.IMAGE)" width="100%" height="100%" :alt="scope.row.TITLE">
           </template>
         </el-table-column>
         <el-table-column type="selection" width="55"></el-table-column>

+ 21 - 21
backendEle/src/views/article/category.vue

@@ -15,29 +15,29 @@
             {{tool.formatDate(scope.row.CREATED_AT)}}
           </template>
         </el-table-column>
-        <el-table-column fixed="right" label="Action" width="180"><!--操作-->
-          <template slot-scope="scope">
-            <el-dropdown size="small" trigger="click">
-              <el-button type="primary" size="small" @click.stop="">
-                Action<i class="el-icon-arrow-down el-icon--right"></i>
-              </el-button>
-              <el-dropdown-menu slot="dropdown">
-                <el-dropdown-item command="edit" @click.native="handleDelete(scope.row)">Delete</el-dropdown-item>
-              </el-dropdown-menu>
-            </el-dropdown>
-          </template>
-        </el-table-column>
+<!--        <el-table-column fixed="right" label="Action" width="180">&lt;!&ndash;操作&ndash;&gt;-->
+<!--          <template slot-scope="scope">-->
+<!--            <el-dropdown size="small" trigger="click">-->
+<!--              <el-button type="primary" size="small" @click.stop="">-->
+<!--                Action<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>-->
+<!--              </el-button>-->
+<!--              <el-dropdown-menu slot="dropdown">-->
+<!--                <el-dropdown-item command="edit" @click.native="handleDelete(scope.row)">Delete</el-dropdown-item>-->
+<!--              </el-dropdown-menu>-->
+<!--            </el-dropdown>-->
+<!--          </template>-->
+<!--        </el-table-column>-->
       </el-table>
       <div class="white-box-footer">
-        <el-dropdown size="small" trigger="click">
-          <el-button type="primary" size="small">
-            Selected data<!--所选数据--><i class="el-icon-arrow-down el-icon--right"></i>
-          </el-button>
-          <el-dropdown-menu slot="dropdown">
-            <el-dropdown-item command="delete" @click.native="handleMuliDel()">Delete</el-dropdown-item>
-          </el-dropdown-menu>
-        </el-dropdown>
-        <el-button type="primary" size="small" @click="handleAdd">New category</el-button><!--新建分类-->
+<!--        <el-dropdown size="small" trigger="click">-->
+<!--          <el-button type="primary" size="small">-->
+<!--            Selected data&lt;!&ndash;所选数据&ndash;&gt;<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>-->
+<!--          </el-button>-->
+<!--          <el-dropdown-menu slot="dropdown">-->
+<!--            <el-dropdown-item command="delete" @click.native="handleMuliDel()">Delete</el-dropdown-item>-->
+<!--          </el-dropdown-menu>-->
+<!--        </el-dropdown>-->
+<!--        <el-button type="primary" size="small" @click="handleAdd">New category</el-button>&lt;!&ndash;新建分类&ndash;&gt;-->
         <el-pagination
           @size-change="handleSizeChange"
           @current-change="handleCurrentChange"

+ 4 - 0
backendEle/src/views/article/detail.vue

@@ -16,6 +16,7 @@ import Vue from 'vue'
 import network from '@/utils/network'
 import tool from '@/utils/tool'
 import store from '@/utils/vuexStore'
+import {SERVER_API_HTTP_TYPE,SERVER_API_DOMAIN} from '@/utils/config'
 
 export default {
   name: 'article_detail',
@@ -46,6 +47,9 @@ export default {
         this.loading = false
       })
     },
+    getLink(fileUrl) {
+      return fileUrl.indexOf('http') > -1 ? fileUrl : SERVER_API_HTTP_TYPE + SERVER_API_DOMAIN + '/uploads/' + fileUrl;
+    },
   }
 }
 

+ 14 - 1
backendEle/src/views/article/index.vue

@@ -3,7 +3,20 @@
     <div class="white-box">
       <el-table :data="tableData" stripe style="width: 100%;" @selection-change="handleSelectionChange">
         <el-table-column type="selection" width="55"></el-table-column>
-        <el-table-column label="Title" prop="TITLE"></el-table-column><!--标题-->
+        <el-table-column label="ID" prop="ID">
+          <template slot-scope="scope">
+            <router-link :to="`/article/detail/${scope.row.ID}`" target="_blank" class="islide">
+              <span>{{ scope.row.ID }}</span>
+            </router-link>
+          </template>
+        </el-table-column>
+        <el-table-column label="Title" prop="TITLE">
+          <template slot-scope="scope">
+            <router-link :to="`/article/detail/${scope.row.ID}`" target="_blank" class="islide">
+              <span>{{ scope.row.TITLE }}</span>
+            </router-link>
+          </template>
+        </el-table-column><!--标题-->
         <el-table-column label="Category"><!--分类-->
           <template slot-scope="scope">
             {{allData.allCategory[scope.row.CID].CATE_NAME}}

+ 1 - 1
common/models/forms/ArticleForm.php

@@ -74,7 +74,7 @@ class ArticleForm extends Model
             } elseif($this->scenario == 'edit') {
                 $model = Article::findOne(['ID'=>$this->id]);
             } else {
-                $this->addError('edit', '提交场景不存在');
+                $this->addError('edit', 'Scenario not exists');// 提交场景不存在
                 return null;
             }
             $model->TITLE = $this->title;

+ 10 - 6
common/models/forms/UploadForm.php

@@ -9,6 +9,7 @@ use common\helpers\Excel;
 use common\helpers\Form;
 use common\helpers\http\RemoteUploadApi;
 use common\helpers\ocr\OcrApi;
+use common\helpers\Tool;
 use common\helpers\user\Info;
 use common\models\ExcelAddUser;
 use common\models\ExcelImport;
@@ -66,6 +67,7 @@ class UploadForm extends Model {
             'invoiceFront' => ['file', 'token', 'remark', 'withdrawId'],
             'proveFront' => ['file', 'token', 'rechargeId'],
             'ad' => ['file', 'token'],
+            'article' => ['file', 'token'],
             'excel' => ['file', 'token', 'excelOption'],
             'goodsImg' => ['file', 'token'],
         ];
@@ -170,21 +172,23 @@ class UploadForm extends Model {
                         'md5' => $uploadResult['md5'] ?? null,
                     ];
                 } else {
-                    throw new Exception('文件远程上传失败');
+                    throw new Exception('Remote service error');
                 }
                 // 删除本地临时文件
                 unlink($this->file->tempName);
             } else {
+                // 生成文件名
+                $fileName = Tool::generateId(false);
                 // 保存在本地
-                $localPath = \Yii::getAlias('@common/runtime/uploads/') . $this->file->baseName . '.' . $this->file->extension;
+                $localPath = \Yii::getAlias('@common/runtime/uploads/') . $fileName . '.' . $this->file->extension;
                 if (!$this->file->saveAs($localPath)) {
-                    throw new Exception('文件保存失败');
+                    throw new Exception('Failed');
                 }
                 $uploadInfo = [
-                    'fileName' => $this->file->baseName . '.' . $this->file->extension,
+                    'fileName' => $fileName . '.' . $this->file->extension,
                     'category' => $uploadCategory,
 //                    'url' => $localPath,
-                    'url' => $this->file->baseName . '.' . $this->file->extension,
+                    'url' => $fileName . '.' . $this->file->extension,
                     'fileSize' => null,
                     'md5' => null,
                 ];
@@ -200,7 +204,7 @@ class UploadForm extends Model {
             $uploads->REMARK = $uploadRemark;
             $uploads->CREATED_AT = Date::nowTime();
             if (!$uploads->save()) {
-                throw new Exception('上传文件信息保存失败');
+                throw new Exception('Save error');
             }
             // 如果是上传发票,更新发票信息,并绑定提现记录
             if ($this->scenario == 'invoiceFront') {

+ 1 - 1
frontendApi/modules/v1/controllers/ArticleController.php

@@ -90,7 +90,7 @@ class ArticleController extends BaseController
             }
             return static::notice($data);
         } else {
-            return static::notice('文章不存在', 400);
+            return static::notice('The article does not exist', 400);// 文章不存在
         }
     }
 }

+ 1 - 1
frontendEle/src/components/Uploader.vue

@@ -94,7 +94,7 @@
     methods: {
       uploaderHandleBefore() {
         this.$message({
-          message: '正在上传,请稍后。请勿关闭窗口!',
+          message: 'Uploading, please hold on. Do not close the window!', // 正在上传,请稍后。请勿关闭窗口!
           type: 'warning',
           duration: 0,
         })

+ 2 - 2
frontendEle/src/views/shop/order.vue

@@ -395,7 +395,7 @@ export default{
             this.form.metadata.custom_fields[0].value = response.SN
             this.visible = true
           }).catch(() => {
-            this.submitButtonStat = true
+            this.submitButtonStat = false
           })
         } else {
           // 非PayStack支付
@@ -403,7 +403,7 @@ export default{
             this.submitButtonStat = false
             this.$router.push({path: `/shop/order-list`})
           }).catch(() => {
-            this.submitButtonStat = true
+            this.submitButtonStat = false
           })
         }
       }).catch(() => {