uploadsketch.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view :style="{marginTop:navH}"></view>
  6. <view @click="toRecord()" style="margin-bottom:20rpx">
  7. <view style="display: flex;justify-content: center;">
  8. <image style="height: 60rpx;width: 60rpx;" src="../../static/img/icon-clock.png"></image>
  9. </view>
  10. <view style="display: flex;justify-content: center;">
  11. <p style="font-size: 32rpx;">查看修改/反馈记录</p>
  12. </view>
  13. </view>
  14. <view style="display: flex;justify-content: center;">
  15. <radio-group @change="chan">
  16. <label v-for="item in radioGroup" :key="item">
  17. <view style="display: inline;margin: 0 20rpx">
  18. <radio :value="item" :checked="item==activeRadio" color="#fdd544" />{{item}}
  19. </view>
  20. </label>
  21. </radio-group>
  22. </view>
  23. <view style="margin: 30rpx;display: flex;justify-content: center;" v-if="activeRadio == '图片'">
  24. <htz-image-upload :max="18" mediaType="image" name="file" :chooseNum="9" v-model="imageData"
  25. @chooseSuccess="ceshiChooseSuccess1">
  26. </htz-image-upload>
  27. </view>
  28. <view style="margin: 30rpx;display: flex;justify-content: center;" v-if="activeRadio == '视频'">
  29. <htz-image-upload :max="1" mediaType="video" name="file" :chooseNum="1" v-model="videoData"
  30. @chooseSuccess="ceshiChooseSuccess2">
  31. </htz-image-upload>
  32. </view>
  33. <uni-easyinput type="text" :inputBorder="false" v-model="title" placeholder="在此填写让人眼前一亮的标题吧"
  34. :placeholderStyle="placeholderStyle">
  35. </uni-easyinput>
  36. <!-- 多行输入框 -->
  37. <view style="padding: 40rpx 30rpx 150rpx;font-size: 12px">
  38. <textarea v-model="text" maxlength="2000" auto-height="true" placeholder="添加正文" />
  39. </view>
  40. <view class="signup">
  41. <button type="default" class="but1" :loading="loading" :class="{'on':item.title == '1',}" @click="submit()">
  42. 提交初稿</button>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import mvBar from "@/components/mys_navBar/mysNavBar";
  48. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue';
  49. import getPolicyEncode from '@/components/obs/getPolicy.js';
  50. import getSignature from '@/components/obs/GetSignature.js';
  51. export default {
  52. components: {
  53. mvBar,
  54. htzImageUpload,
  55. },
  56. data() {
  57. return {
  58. placeholderStyle: "font-size:16px",
  59. navH: getApp().globalData.navHeight,
  60. taskId: "",
  61. title: "",
  62. text: "",
  63. sketchStatus: "",
  64. activeRadio: '图片', //存的是选中的value值
  65. radioGroup: ['图片', '视频'],
  66. videoData: [],
  67. imageData: [],
  68. mysNavConfig: {
  69. /* 开启单页显示首页图标 */
  70. isHome: true,
  71. /* 固定导航 */
  72. navFixed: true,
  73. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  74. navTitle: {
  75. text: "上传初稿",
  76. color: "",
  77. fontSize: "32rpx", // px upx rpx
  78. fontWeight: "normal", // 100 - 700
  79. },
  80. btnType: "type2",
  81. onLeftClick: '',
  82. /* type2 按钮 */
  83. type2Config: {
  84. // 左图标
  85. leftPath: "/static/img/png2.png",
  86. // 右图标
  87. rightPath: "/static/img/png4.png",
  88. // 圆角
  89. radius: "40rpx",
  90. },
  91. },
  92. }
  93. },
  94. onLoad(options) {
  95. let data = options.textObj.replace(/""/g, "");
  96. data = JSON.parse(decodeURIComponent(data))
  97. this.taskId = data.taskId
  98. this.sketchStatus = data.sketchStatus
  99. this.getSketch()
  100. },
  101. methods: {
  102. chan(e) {
  103. this.activeRadio = e.detail.value;
  104. console.log(this.activeRadio);
  105. },
  106. getSketch() {
  107. this.$https.get('/youngee/c/t/g/get-unsubmit-task-sketch' +
  108. "?" +
  109. "task_id" +
  110. "=" +
  111. this.taskId)
  112. .then(res => {
  113. console.log(res)
  114. if (res.data.data != null) {
  115. this.title = res.data.data.title
  116. this.text = res.data.data.content
  117. if (res.data.data.type == 1) { // 图片
  118. this.activeRadio = '图片'
  119. for (var j = 0; j < res.data.data.Photo.length; j++) {
  120. this.imageData.push(res.data.data.Photo[j].photo_url)
  121. }
  122. } else if (res.data.data.type == 2) { //视频
  123. this.activeRadio = '视频'
  124. for (var j = 0; j < res.data.data.Photo.length; j++) {
  125. this.videoData.push(res.data.data.Photo[j].photo_url)
  126. }
  127. }
  128. }
  129. })
  130. },
  131. toRecord() {
  132. var data = {
  133. taskId: this.taskId,
  134. };
  135. data = JSON.stringify(data)
  136. uni.navigateTo({
  137. url: '/pages/workspace/sketchrecord?textObj=' + encodeURIComponent(data)
  138. });
  139. },
  140. submit() {
  141. // 检验标题和内容是否为空
  142. let type = 0
  143. let photourl = []
  144. if (this.activeRadio == '图片') { // 图片
  145. type = 1
  146. photourl = this.imageData
  147. } else {
  148. type = 2
  149. photourl = this.videoData
  150. }
  151. if (this.title == '') {
  152. uni.showToast({
  153. title: "请填写初稿标题",
  154. icon: 'none'
  155. })
  156. return
  157. }
  158. if (this.text == '') {
  159. uni.showToast({
  160. title: "请填写初稿内容",
  161. icon: 'none'
  162. })
  163. return
  164. }
  165. if (photourl.length == 0) {
  166. uni.showToast({
  167. title: "请上传初稿图片或视频",
  168. icon: 'none'
  169. })
  170. return
  171. }
  172. console.log("photourl:", photourl)
  173. this.$https.post('/youngee/c/t/p/add-task-sketch', {
  174. task_id: this.taskId,
  175. title: this.title,
  176. content: this.text,
  177. type: type,
  178. photo_url: photourl.toString()
  179. })
  180. .then(res => {
  181. console.log(res)
  182. uni.navigateBack()
  183. })
  184. },
  185. ceshiChooseSuccess1(tempFilePaths, e) { //选择图片返回
  186. console.log('ceshiChooseSuccess', tempFilePaths, e);
  187. /****************
  188. 以下代码是自定义上传逻辑,仅供参考
  189. ***************/
  190. this.imgUpload1(tempFilePaths, e);
  191. /*******************************/
  192. console.log("imgdata" + this.imageData)
  193. },
  194. imgUpload1(tempFilePaths, e) {
  195. let that = this
  196. console.log('imgUpload', tempFilePaths)
  197. let config = {
  198. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  199. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  200. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  201. };
  202. for (let i = 0; i < tempFilePaths.length; ++i) {
  203. if (e == 0) {
  204. this.store = 'talent_upload/' + this.guid() + '.png'
  205. } else if (e == 1) {
  206. this.store = 'talent_upload/' + this.guid() + '.mp4'
  207. }
  208. let fileName = this.store; //指定上传到OBS桶中的对象名
  209. let OBSPolicy = { //设定policy内容
  210. "expiration": "2089-12-31T12:00:00.000Z",
  211. "conditions": [{
  212. "bucket": "horastar"
  213. }, //Bucket name
  214. // {"bucket": "goin"},
  215. {
  216. 'key': fileName
  217. }
  218. ]
  219. }
  220. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  221. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  222. uni.uploadFile({
  223. //url: config.EndPoint,
  224. url: config.EndPoint,
  225. filePath: tempFilePaths[i],
  226. name: 'file',
  227. formData: {
  228. 'AccessKeyID': config.AccessKeyId,
  229. 'policy': policyEncoded,
  230. 'signature': signature,
  231. 'key': fileName,
  232. },
  233. success: function(res) {
  234. console.log(res.statusCode); //打印响应状态码
  235. if (res.statusCode == '204') {
  236. that.imageData.push(config.EndPoint + '/' + fileName);
  237. console.log('上传图片成功', res)
  238. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  239. console.log(obs_url)
  240. // that.formData.home_img = obs_url
  241. uni.showToast({
  242. title: '上传成功',
  243. icon: '成功'
  244. });
  245. } else {
  246. console.log('上传图片失败', res)
  247. uni.showToast({
  248. title: '上传失败',
  249. icon: '失败'
  250. });
  251. }
  252. },
  253. fail: function(e) {
  254. console.log(e);
  255. uni.showToast({
  256. title: '上传失败22222',
  257. icon: '失败'
  258. });
  259. }
  260. })
  261. }
  262. },
  263. ceshiChooseSuccess2(tempFilePaths, e) { //选择视频返回
  264. console.log('ceshiChooseSuccess', tempFilePaths, e);
  265. if (e == 0) {
  266. this.store = 'talent_upload/' + this.guid() + '.png'
  267. } else if (e == 1) {
  268. this.store = 'talent_upload/' + this.guid() + '.mp4'
  269. }
  270. /****************
  271. 以下代码是自定义上传逻辑,仅供参考
  272. ***************/
  273. this.imgUpload2(tempFilePaths);
  274. /*******************************/
  275. console.log("videoData" + this.videoData)
  276. },
  277. imgUpload2(tempFilePaths) {
  278. let that = this
  279. console.log('videoUpload', tempFilePaths)
  280. let config = {
  281. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  282. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  283. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  284. };
  285. let fileName = this.store; //指定上传到OBS桶中的对象名
  286. // let fileName = "talent_upload/icon-arrow-right.png"
  287. let OBSPolicy = { //设定policy内容
  288. "expiration": "2089-12-31T12:00:00.000Z",
  289. "conditions": [{
  290. "bucket": "horastar"
  291. }, //Bucket name
  292. // {"bucket": "goin"},
  293. {
  294. 'key': fileName
  295. }
  296. ]
  297. }
  298. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  299. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  300. uni.uploadFile({
  301. //url: config.EndPoint,
  302. url: config.EndPoint,
  303. filePath: tempFilePaths[0],
  304. name: 'file',
  305. formData: {
  306. 'AccessKeyID': config.AccessKeyId,
  307. 'policy': policyEncoded,
  308. 'signature': signature,
  309. 'key': fileName,
  310. },
  311. success: function(res) {
  312. console.log(res.statusCode); //打印响应状态码
  313. if (res.statusCode == '204') {
  314. that.videoData.push(config.EndPoint + '/' + fileName);
  315. console.log('上传图片成功', res)
  316. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  317. console.log(obs_url)
  318. // that.formData.home_img = obs_url
  319. uni.showToast({
  320. title: '上传成功',
  321. icon: '成功'
  322. });
  323. } else {
  324. console.log('上传图片失败', res)
  325. uni.showToast({
  326. title: '上传失败',
  327. icon: '失败'
  328. });
  329. }
  330. },
  331. fail: function(e) {
  332. console.log(e);
  333. uni.showToast({
  334. title: '上传失败22222',
  335. icon: '失败'
  336. });
  337. }
  338. })
  339. },
  340. guid() {
  341. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  342. var r = Math.random() * 16 | 0,
  343. v = c == 'x' ? r : (r & 0x3 | 0x8);
  344. return v.toString(16);
  345. });
  346. },
  347. },
  348. }
  349. </script>
  350. <style lang="scss" scoped>
  351. .signup {
  352. box-shadow: 0rpx 5rpx 40rpx #ccc;
  353. width: 100%;
  354. position: fixed;
  355. bottom: 0rpx;
  356. display: flex;
  357. height: 90rpx;
  358. padding-top: 2%;
  359. background-color: #FFFFFF;
  360. z-index: 99;
  361. }
  362. .but1 {
  363. width: 60%;
  364. background-color: #f2d22d;
  365. border-radius: 20rpx;
  366. font-size: 36rpx;
  367. line-height: 200%;
  368. letter-spacing: 10rpx;
  369. font-weight: 500;
  370. height: 80%;
  371. &.on {
  372. background-color: #C0C0C0;
  373. }
  374. }
  375. </style>